Exemplo n.º 1
0
        public async Task <IActionResult> UpdateSectionAsync([FromBody] UpdateSectionManagementAc updateSectionManagement)
        {
            if (string.IsNullOrEmpty(updateSectionManagement.Name.Trim()))
            {
                return(Ok(new SharedLookUpResponse {
                    ErrorType = SharedLookUpResponseType.Name, HasError = true, Message = "Section name can't be empty"
                }));
            }
            else if (string.IsNullOrEmpty(updateSectionManagement.Code.Trim()))
            {
                return(Ok(new SharedLookUpResponse {
                    ErrorType = SharedLookUpResponseType.Code, HasError = true, Message = "Section name can't be empty"
                }));
            }
            else
            {
                var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

                if (await _iMSDbContext.Sections.AnyAsync(x => x.Id == updateSectionManagement.SectionId && x.InstituteId == loggedInUserInstituteId))
                {
                    return(Ok(await _sectionManagementRepository.UpdateSectionAsync(updateSectionManagement, loggedInUserInstituteId)));
                }
                else
                {
                    return(Ok(new SharedLookUpResponse {
                        HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Section not found"
                    }));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to update Section - SS
        /// </summary>
        /// <param name="updateSectionManagement">Section detail</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> UpdateSectionAsync(UpdateSectionManagementAc updateSectionManagement, int instituteId)
        {
            var sections = await _iMSDbContext.Sections.Where(x => x.InstituteId == instituteId && x.Id != updateSectionManagement.SectionId).ToListAsync();

            var isDuplicate = sections.Any(x => x.Code.ToLowerInvariant() == updateSectionManagement.Code.ToLowerInvariant());

            if (isDuplicate)
            {
                return new SharedLookUpResponse()
                       {
                           HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate code of section. Please use unique code"
                       }
            }
            ;
            else
            {
                var section = await _iMSDbContext.Sections.FirstAsync(x => x.Id == updateSectionManagement.SectionId);

                section.Name        = updateSectionManagement.Name;
                section.Code        = updateSectionManagement.Code;
                section.Description = updateSectionManagement.Description;
                section.Status      = updateSectionManagement.Status;
                _iMSDbContext.Sections.Update(section);
                await _iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "Section updated successfully"
                });
            }
        }