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

                if (await _iMSDbContext.Castes.AnyAsync(x => x.Id == updateCasteManagement.CasteId && x.InstituteId == loggedInUserInstituteId))
                {
                    return(Ok(await _casteManagementRepository.UpdateCasteAsync(updateCasteManagement, loggedInUserInstituteId)));
                }
                else
                {
                    return(Ok(new SharedLookUpResponse {
                        HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Caste not found"
                    }));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to update Caste - SS
        /// </summary>
        /// <param name="updateCasteManagement">Caste detail</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> UpdateCasteAsync(UpdateCasteManagementAc updateCasteManagement, int instituteId)
        {
            var castes = await _iMSDbContext.Castes.Where(x => x.InstituteId == instituteId && x.Id != updateCasteManagement.CasteId).ToListAsync();

            var isDuplicate = castes.Any(x => x.Code.ToLowerInvariant() == updateCasteManagement.Code.ToLowerInvariant());

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

                caste.Name        = updateCasteManagement.Name;
                caste.Code        = updateCasteManagement.Code;
                caste.Description = updateCasteManagement.Description;
                caste.Status      = updateCasteManagement.Status;
                _iMSDbContext.Castes.Update(caste);
                await _iMSDbContext.SaveChangesAsync();

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