public async Task <bool> UpdateFarmerAsync(int id, FarmerModelRq model, UserIdentity <int> issuer) { try { var entity = _mapper.Map <Farmer>(model); entity = await _FarmerRepository.GetEntityByIdAsync(id); if (entity == null) { return(false); } _mapper.Map(model, entity); entity.UpdateBy(issuer); _FarmerRepository.Update(entity); if (await _uow.SaveChangesAsync() == 1) { return(true); } return(false); } catch (Exception e) { throw e; } }
public async Task <IActionResult> UpdateFarmerAsync(int id, [FromBody] FarmerModelRq model) { var issuer = GetCurrentUserIdentity <int>(); try { return(Ok(await _FarmerService.UpdateFarmerAsync(id, model, issuer))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> CreateFarmerAsync([FromBody] FarmerModelRq model) { var issuer = GetCurrentUserIdentity <int>(); try { if (await _FarmerService.CheckCodeExistsAsync(model.Code)) { return(BadRequest("Code Exists")); } return(Ok(await _FarmerService.CreateFarmerAsync(model, issuer))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <int> CreateFarmerAsync(FarmerModelRq model, UserIdentity <int> issuer) { try { var entity = _mapper.Map <Farmer>(model); entity.CreateBy(issuer).UpdateBy(issuer); _FarmerRepository.Create(entity); if (await _uow.SaveChangesAsync() == 1) { return(entity.Id); } return(0); } catch (Exception e) { throw e; } }