/// <summary>
        /// Method to add BloodGroup - SS
        /// </summary>
        /// <param name="name">name of BloodGroup</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> AddBloodGroupAsync(AddBloodGroupManagementAc addBloodGroup, int instituteId)
        {
            if (!await _iMSDbContext.BloodGroups.AnyAsync(x => x.InstituteId == instituteId && x.Code.ToLowerInvariant() == addBloodGroup.Code.ToLowerInvariant()))
            {
                var bloodGroup = new BloodGroup()
                {
                    CreatedOn   = DateTime.UtcNow,
                    InstituteId = instituteId,
                    Name        = addBloodGroup.Name,
                    Code        = addBloodGroup.Code,
                    Description = addBloodGroup.Description,
                    Status      = true
                };
                _iMSDbContext.BloodGroups.Add(bloodGroup);
                await _iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "Blood group added successfully"
                });
            }
            else
            {
                return new SharedLookUpResponse()
                       {
                           HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Blood group with the same code is already exist"
                       }
            };
        }
Esempio n. 2
0
 public async Task <IActionResult> AddBloodGroupAsync([FromBody] AddBloodGroupManagementAc addBloodGroupManagement)
 {
     if (string.IsNullOrEmpty(addBloodGroupManagement.Name.Trim()))
     {
         return(Ok(new SharedLookUpResponse()
         {
             HasError = true, ErrorType = SharedLookUpResponseType.Name, Message = "Blood group name can't be null or empty"
         }));
     }
     else if (string.IsNullOrEmpty(addBloodGroupManagement.Code.Trim()))
     {
         return(Ok(new SharedLookUpResponse()
         {
             HasError = true, ErrorType = SharedLookUpResponseType.Name, Message = "Blood group code can't be null or empty"
         }));
     }
     else
     {
         return(Ok(await _bloodGroupManagementRepository.AddBloodGroupAsync(addBloodGroupManagement, await GetUserCurrentSelectedInstituteIdAsync())));
     }
 }