Exemple #1
0
        public async Task <IActionResult> UpdateProvinceAsync(int id, [FromBody] ProvinceModelRq model)
        {
            var issuer = GetCurrentUserIdentity <int>();

            try
            {
                return(Ok(await _provinceService.UpdateProvinceAsync(id, model, issuer)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #2
0
 public async Task <int> CreateProvinceAsync(ProvinceModelRq model, UserIdentity <int> issuer)
 {
     try
     {
         var province = _mapper.Map <Province>(model);
         province.CreateBy(issuer).UpdateBy(issuer);
         _provinceRepository.Create(province);
         if (await _uow.SaveChangesAsync() == 1)
         {
             return(province.Id);
         }
         return(0);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #3
0
        public async Task <bool> UpdateProvinceAsync(int id, ProvinceModelRq model, UserIdentity <int> issuer)
        {
            try
            {
                var province = await _provinceRepository.GetEntityByIdAsync(id);

                if (province == null)
                {
                    throw new Exception("Not Found");
                }
                _mapper.Map(model, province);
                _provinceRepository.Update(province);
                province.UpdateBy(issuer);
                if (await _uow.SaveChangesAsync() == 1)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }