/// <summary>
        /// Method to update BloodGroup - SS
        /// </summary>
        /// <param name="updateBloodGroupManagement">BloodGroup detail</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> UpdateBloodGroupAsync(UpdateBloodGroupManagementAc updateBloodGroupManagement, int instituteId)
        {
            var bloodGroups = await _iMSDbContext.BloodGroups.Where(x => x.InstituteId == instituteId && x.Id != updateBloodGroupManagement.BloodGroupId).ToListAsync();

            var isDuplicate = bloodGroups.Any(x => x.Code.ToLowerInvariant() == updateBloodGroupManagement.Code.ToLowerInvariant());

            if (isDuplicate)
            {
                return new SharedLookUpResponse()
                       {
                           HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate code of Blood group. Please use unique code"
                       }
            }
            ;
            else
            {
                var bloodGroup = await _iMSDbContext.BloodGroups.FirstAsync(x => x.Id == updateBloodGroupManagement.BloodGroupId);

                bloodGroup.Name        = updateBloodGroupManagement.Name;
                bloodGroup.Code        = updateBloodGroupManagement.Code;
                bloodGroup.Description = updateBloodGroupManagement.Description;
                bloodGroup.Status      = updateBloodGroupManagement.Status;
                _iMSDbContext.BloodGroups.Update(bloodGroup);
                await _iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    Message = "Blood group updated successfully", HasError = false
                });
            }
        }
예제 #2
0
        public async Task <IActionResult> UpdateBloodGroupAsync([FromBody] UpdateBloodGroupManagementAc updateBloodGroupManagement)
        {
            if (string.IsNullOrEmpty(updateBloodGroupManagement.Name.Trim()))
            {
                return(Ok(new SharedLookUpResponse {
                    ErrorType = SharedLookUpResponseType.Name, HasError = true, Message = "Blood group name can't be null or empty"
                }));
            }
            else if (string.IsNullOrEmpty(updateBloodGroupManagement.Code.Trim()))
            {
                return(Ok(new SharedLookUpResponse()
                {
                    HasError = true, ErrorType = SharedLookUpResponseType.Name, Message = "Blood group code can't be null or empty"
                }));
            }
            else
            {
                var instituteId = await GetUserCurrentSelectedInstituteIdAsync();

                if (await _iMSDbContext.BloodGroups.AnyAsync(x => x.Id == updateBloodGroupManagement.BloodGroupId && x.InstituteId == instituteId))
                {
                    return(Ok(await _bloodGroupManagementRepository.UpdateBloodGroupAsync(updateBloodGroupManagement, await GetUserCurrentSelectedInstituteIdAsync())));
                }
                else
                {
                    return(Ok(new SharedLookUpResponse {
                        HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Blood group not found"
                    }));
                }
            }
        }