/// <summary>
        /// Method to update state - SS
        /// </summary>
        /// <param name="updateAdministrationState">state detail</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> UpdateInstituteStateAsync(UpdateAdministrationStateAc updateAdministrationState)
        {
            var states = await _iMSDbContext.AdministrationStates.Where(x => x.CountryId == updateAdministrationState.CountryId &&
                                                                        x.Id != updateAdministrationState.StateId).ToListAsync();

            var isDuplicate = states.Any(x => x.Code.ToLowerInvariant() == updateAdministrationState.Code.ToLowerInvariant());

            if (isDuplicate)
            {
                return new SharedLookUpResponse()
                       {
                           HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate code of state. Please use unique code"
                       }
            }
            ;
            else
            {
                var state = await _iMSDbContext.AdministrationStates.FirstAsync(x => x.Id == updateAdministrationState.StateId);

                state.Name        = updateAdministrationState.Name;
                state.CountryId   = updateAdministrationState.CountryId;
                state.Code        = updateAdministrationState.Code;
                state.Description = updateAdministrationState.Description;
                state.Status      = updateAdministrationState.Status;
                _iMSDbContext.AdministrationStates.Update(state);
                await _iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "State updated successfully"
                });
            }
        }
예제 #2
0
        public async Task <IActionResult> UpdateInstituteStateAsync([FromBody] UpdateAdministrationStateAc state)
        {
            var stateDetail = await _iMSDbContext.AdministrationStates.FirstOrDefaultAsync(x => x.Id == state.StateId);

            if (stateDetail != null)
            {
                var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

                if (await _iMSDbContext.AdministrationCountries.AnyAsync(x => x.InstituteId == loggedInUserInstituteId && x.Id == state.CountryId))
                {
                    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
                    {
                        return(Ok(await _instituteCountryStateCityManagementRepository.UpdateInstituteStateAsync(state)));
                    }
                }
                else
                {
                    return(Ok(new SharedLookUpResponse {
                        ErrorType = SharedLookUpResponseType.Other, HasError = true, Message = "Invalid country selection"
                    }));
                }
            }
            else
            {
                return(Ok(new SharedLookUpResponse {
                    ErrorType = SharedLookUpResponseType.Other, HasError = true, Message = "State not found"
                }));
            }
        }