/// <summary>
        /// Method to add country - SS
        /// </summary>
        /// <param name="countryName">country name</param>
        /// <param name="instituteId">institute id</param>
        /// <returns>message</returns>
        public async Task <SharedLookUpResponse> AddInstituteCountryAsync(AddAdministrationCountryAc addAdministrationCountry, int instituteId)
        {
            if (!(await _iMSDbContext.AdministrationCountries.AnyAsync(x => x.Code.ToLowerInvariant() ==
                                                                       addAdministrationCountry.Code.ToLowerInvariant() && x.InstituteId == instituteId)))
            {
                var country = new AdministrationCountry()
                {
                    CreatedOn   = DateTime.UtcNow,
                    InstituteId = instituteId,
                    Name        = addAdministrationCountry.Name,
                    Code        = addAdministrationCountry.Code,
                    Description = addAdministrationCountry.Description,
                    Status      = true
                };
                _iMSDbContext.AdministrationCountries.Add(country);
                await _iMSDbContext.SaveChangesAsync();

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

                return(Ok(await _instituteCountryStateCityManagementRepository.AddInstituteCountryAsync(country, loggedInUserInstituteId)));
            }
        }