public async Task <ActionResult <CommonAPIResponse <bool> > > AddCountry(CountryAddDTO CountryAddDTO)
        {
            #region Declare return type with initial value.
            JsonResult jsonResult = GetDefaultJsonResult <bool>();
            #endregion

            try
            {
                #region Validate AddCountry for nullability before prepaing the response.

                if (await CountryAppService.AddCountry(CountryAddDTO))
                {
                    jsonResult = JsonResultResponse(CommonHelper.GetResponseMessage(APIResponseMessage.Success, CurrentLanguagId), true, HttpStatusCode.OK);
                }
                else
                {
                    jsonResult = JsonResultResponse(CommonHelper.GetResponseMessage(APIResponseMessage.InvalidCredentials, CurrentLanguagId), false, HttpStatusCode.BadRequest);
                }
                #endregion
            }
            catch (Exception exception)
            {
            }
            return(jsonResult);
        }
 /// <summary>
 /// Add Country AppService
 /// </summary>
 /// <returns>bool<bool></returns>
 public async Task <bool> AddCountry(CountryAddDTO countryAddDTO)
 {
     #region Declare a return type with initial value.
     bool isCreated = false;
     #endregion
     try
     {
         if (countryAddDTO != null)
         {
             isCreated = await CountryBusinessMapping.AddCountry(countryAddDTO);
         }
     }
     catch (Exception exception) {}
     return(isCreated);
 }
Example #3
0
 /// <summary>
 /// Mapping user Action Actitvity Log
 /// </summary>
 /// <param name=></ param >
 /// <returns>Task<Country></returns>
 public Country MappingCountryAddDTOToCountry(CountryAddDTO CountryAddDTO)
 {
     #region Declare a return type with initial value.
     Country Country = null;
     #endregion
     try
     {
         Country = new Country
         {
             CountryName  = CountryAddDTO.CountryName,
             CreationDate = DateTime.Now,
             IsDeleted    = (byte)DeleteStatusEnum.NotDeleted
         };
     }
     catch (Exception exception) { }
     return(Country);
 }
        /// <summary>
        /// Create User Action Activity Log
        /// </summary>
        /// <param name=></param>
        /// <returns>bool</returns>
        public async Task <bool> AddCountry(CountryAddDTO CountryAddDTO)
        {
            #region Declare a return type with initial value.
            bool isCountryCreated = default(bool);
            #endregion
            try
            {
                #region Vars
                Country Country = null;
                #endregion
                Country = CountryMapping.MappingCountryAddDTOToCountry(CountryAddDTO);
                if (Country != null)
                {
                    await UnitOfWork.CountryRepository.Insert(Country);

                    isCountryCreated = await UnitOfWork.Commit() > default(int);
                }
            }
            catch (Exception exception)
            {
            }
            return(isCountryCreated);
        }
        public IActionResult Post([FromBody] CountryAddDTO country)
        {
            if (country == null)
            {
                return(BadRequest(new ErrorViewModel
                {
                    ErrorCode = "400",
                    ErrorMessage = "Thông tin cung cấp không chính xác."
                }));
            }

            if (!ModelState.IsValid)
            {
                var errorViewModel = new ErrorViewModel
                {
                    ErrorCode    = "400",
                    ErrorMessage = ModelState.ToErrorMessages()
                };

                return(BadRequest(errorViewModel));
            }

            bool isExisting = this._countryRepository.CheckExistingCode(country.Code);

            if (isExisting)
            {
                return(BadRequest(new ErrorViewModel
                {
                    ErrorCode = "400",
                    ErrorMessage = "Mã quốc gia này đã tồn tại."
                }));
            }

            isExisting = this._countryRepository.CheckExistingName("", country.Name);
            if (isExisting)
            {
                return(BadRequest(new ErrorViewModel
                {
                    ErrorCode = "400",
                    ErrorMessage = "Tên quốc gia này đã tồn tại."
                }));
            }

            var newCountry = new Country
            {
                Code        = country.Code,
                Name        = country.Name,
                CreatedBy   = "admin",
                CreatedDate = DateTime.Now,
                UpdatedBy   = "admin",
                UpdatedDate = DateTime.Now
            };

            bool isSuccess = this._countryRepository.Insert(newCountry);

            if (isSuccess == false)
            {
                return(StatusCode(500, new ErrorViewModel
                {
                    ErrorCode = "500",
                    ErrorMessage = "Có lỗi trong quá trình cập nhật dữ liệu."
                }));
            }

            return(Ok(newCountry));
        }