Exemplo n.º 1
0
        /// <summary>
        /// Method for updating mother tongue
        /// </summary>
        /// <param name="id"></param>
        /// <param name="updatedMotherTongue"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <SharedLookUpResponse> UpdateMotherTongueAsync(int id, MotherTongueAc updatedMotherTongueAc, ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            MotherTongue motherTongue = await _imsDbContext.MotherTongues.FirstOrDefaultAsync(x => x.Id == id && x.InstituteId == currentUserInstituteId);

            if (motherTongue == null)
            {
                return(new SharedLookUpResponse {
                    Message = "No mother tongue exists with this id", HasError = true
                });
            }
            else if (await _imsDbContext.MotherTongues.AnyAsync(x => x.Language.ToLowerInvariant().Equals(updatedMotherTongueAc.Name.ToLowerInvariant()) &&
                                                                x.Id != id && x.InstituteId == currentUserInstituteId))
            {
                return(new SharedLookUpResponse {
                    Message = "Mother tongue already exists with this name", HasError = true, ErrorType = SharedLookUpResponseType.Name
                });
            }
            else if (await _imsDbContext.MotherTongues.AnyAsync(x => x.Code.ToLowerInvariant().Equals(updatedMotherTongueAc.Code.ToLowerInvariant()) &&
                                                                x.Id != id && x.InstituteId == currentUserInstituteId))
            {
                return(new SharedLookUpResponse {
                    Message = "Mother tongue already exists with this code", HasError = true, ErrorType = SharedLookUpResponseType.Code
                });
            }

            motherTongue.Language    = updatedMotherTongueAc.Name;
            motherTongue.Code        = updatedMotherTongueAc.Code;
            motherTongue.Description = updatedMotherTongueAc.Description;
            motherTongue.Status      = true;
            _imsDbContext.MotherTongues.Update(motherTongue);
            await _imsDbContext.SaveChangesAsync();

            return(new SharedLookUpResponse {
                Message = "Mother tongue updated successfully", HasError = false
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method for adding new mother tongue
        /// </summary>
        /// <param name="newMotherTongue"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <SharedLookUpResponse> AddMotherTongueAsync(MotherTongueAc newMotherTongueAc, ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

            if (await _imsDbContext.MotherTongues.AnyAsync(x => x.Language.ToLowerInvariant().Equals(newMotherTongueAc.Name.ToLowerInvariant()) &&
                                                           x.InstituteId == currentUserInstituteId))
            {
                return(new SharedLookUpResponse {
                    Message = "Mother tongue already exists with this name", HasError = true, ErrorType = SharedLookUpResponseType.Name
                });
            }
            else if (await _imsDbContext.MotherTongues.AnyAsync(x => x.Code.ToLowerInvariant().Equals(newMotherTongueAc.Code.ToLowerInvariant()) &&
                                                                x.InstituteId == currentUserInstituteId))
            {
                return(new SharedLookUpResponse {
                    Message = "Mother tongue already exists with this code", HasError = true, ErrorType = SharedLookUpResponseType.Code
                });
            }

            MotherTongue newMotherTongue = new MotherTongue
            {
                Code        = newMotherTongueAc.Code,
                Language    = newMotherTongueAc.Name,
                Description = newMotherTongueAc.Description,
                Status      = true,
                InstituteId = currentUserInstituteId,
                CreatedBy   = currentUser.Id,
                CreatedOn   = DateTime.UtcNow
            };

            _imsDbContext.MotherTongues.Add(newMotherTongue);
            await _imsDbContext.SaveChangesAsync();

            return(new SharedLookUpResponse {
                HasError = false, Message = "Blood group added successfully"
            });
        }
        public async Task <IActionResult> UpdateMotherTongueAsync(int id, [FromBody] MotherTongueAc updatedMotherTongueAc)
        {
            ApplicationUser currentUser = await _userManager.FindByEmailAsync(User.Identity.Name);

            return(Ok(await _motherTongueManagementRepository.UpdateMotherTongueAsync(id, updatedMotherTongueAc, currentUser)));
        }