Esempio n. 1
0
        /// <summary>
        /// Method for fetching mother tongue by id
        /// </summary>
        /// <param name="id"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <MotherTongueAc> GetMotherTongueByIdAsync(int id, ApplicationUser currentUser)
        {
            int currentUserInstituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(currentUser.Id, true);

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

            return((motherTongue == null)
                ? null
                : new MotherTongueAc
            {
                Id = motherTongue.Id,
                Name = motherTongue.Language,
                Code = motherTongue.Code,
                Description = motherTongue.Description,
                Status = motherTongue.Status,
                CreatedOn = motherTongue.CreatedOn
            });
        }
Esempio n. 2
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
            });
        }
Esempio n. 3
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"
            });
        }
Esempio n. 4
0
partial         void MotherTongues_Inserting(MotherTongue entity)
        {
            entity.InsertDate = DateTime.Now;
            entity.InsertUser = Application.User.Name;
            entity.UpdateDate = DateTime.Now;
            entity.UpdateUser = Application.User.Name;
        }