コード例 #1
0
        /// <summary>
        /// Method to add state - SS
        /// </summary>
        /// <param name="state">state detail</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> AddInstituteStateAsync(AddAdministrationStateAc state)
        {
            if (!(await _iMSDbContext.AdministrationStates.AnyAsync(x => x.Code.ToLowerInvariant() == state.Code.ToLowerInvariant() &&
                                                                    x.CountryId == state.CountryId)))
            {
                var stateDetail = new AdministrationState()
                {
                    CreatedOn   = DateTime.UtcNow,
                    CountryId   = state.CountryId,
                    Name        = state.Name,
                    Code        = state.Code,
                    Description = state.Description,
                    Status      = true
                };
                _iMSDbContext.AdministrationStates.Add(stateDetail);
                await _iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "State added successfully"
                });
            }
            else
            {
                return new SharedLookUpResponse()
                       {
                           HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "State code already exist"
                       }
            };
        }
コード例 #2
0
        public async Task <IActionResult> AddInstituteStateAsync([FromBody] AddAdministrationStateAc state)
        {
            if (string.IsNullOrEmpty(state.Name.Trim()))
            {
                return(Ok(new SharedLookUpResponse {
                    ErrorType = SharedLookUpResponseType.Name, HasError = true, Message = "State name can't be null or empty"
                }));
            }
            else if (string.IsNullOrEmpty(state.Code.Trim()))
            {
                return(Ok(new SharedLookUpResponse {
                    ErrorType = SharedLookUpResponseType.Code, HasError = true, Message = "State code can't be null or empty"
                }));
            }
            else
            {
                var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

                if (await _iMSDbContext.AdministrationCountries.AnyAsync(x => x.Id == state.CountryId && x.InstituteId == loggedInUserInstituteId))
                {
                    return(Ok(await _instituteCountryStateCityManagementRepository.AddInstituteStateAsync(state)));
                }
                else
                {
                    return(Ok(new SharedLookUpResponse {
                        ErrorType = SharedLookUpResponseType.Other, HasError = true, Message = "Invalid country selection"
                    }));
                }
            }
        }