public async Task <IHttpActionResult> Put(string id, NvCongNoVm.Dto instance) { TransferObj <NvCongNo> result = new TransferObj <NvCongNo>(); NvCongNo check = _service.FindById(instance.Id); if (id != instance.Id || check.TrangThai == (int)ApprovalState.IsComplete) { result.Status = false; result.Message = "Dữ liệu không đúng!"; return(Ok(result)); } try { NvCongNo item = _service.UpdatePhieu(instance); await _service.UnitOfWork.SaveAsync(); result.Status = true; result.Message = "Update thành công!"; result.Data = item; } catch (Exception e) { WriteLogs.LogError(e); result.Status = false; result.Message = e.Message.ToString(); } return(Ok(result)); }
public async Task <IHttpActionResult> GetDetails(string id) { TransferObj <NvCongNoVm.Dto> result = new TransferObj <NvCongNoVm.Dto>(); NvCongNoVm.Dto temp = new NvCongNoVm.Dto(); NvCongNo phieu = _service.FindById(id); if (phieu != null) { temp = Mapper.Map <NvCongNo, NvCongNoVm.Dto>(phieu); result.Data = temp; result.Status = true; return(Ok(result)); } return(NotFound()); }
public async Task <IHttpActionResult> Post(NvCongNoVm.Dto instance) { TransferObj <NvCongNo> result = new TransferObj <NvCongNo>(); try { NvCongNo item = _service.InsertPhieu(instance); await _service.UnitOfWork.SaveAsync(); result.Data = item; result.Message = "Thêm mới thành công"; result.Status = true; return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.Id }, result)); } catch (Exception e) { WriteLogs.LogError(e); result.Message = e.Message.ToString(); result.Status = false; } return(Ok(result)); }