bihanviranga / helpdesk

A HelpDesk system REST API for managing client support tickets across multiple organizations/products/brands.
0 stars 0 forks source link

Using fail first coding Principle #52

Open nishanc opened 4 years ago

nishanc commented 4 years ago

https://github.com/bihanviranga/helpdesk/blob/cfbcfaff59f42b44e33ad859dfacb41f66281936/HelpDesk/Controllers/ModuleController.cs#L106

It’s a clean code practice to write to failing part of the code first to make the code cleaner and have less indent

                if (userRole == "Client")
                    return StatusCode(401, "401 Unauthorized  Access");

                if (userRole == "Manager")
                {
                    var modules = await _repository.Module.GetModuleByCondition(userType, userCompanyId);
                    foreach (var module in modules)
                    {
                        var TempModuleDto = _mapper.Map<ModuleDto>(module);
                        if (module.CompanyId != null)
                        {
                            var company = await _repository.Company.GetCompanyById(new Guid(module.CompanyId));
                            if (company != null)
                            {
                                TempModuleDto.CompanyName = company.CompanyName;
                                ModuleList.Add(TempModuleDto);
                            }
                        }
                    }
                    return Ok(ModuleList);
                }

                else
                {
                    return StatusCode(500, "Something went wrong");
                }
nishanc commented 4 years ago

More details here