public JsonResult CreateOrUpDate(DonThuocEntities Option) { var result = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; try { if (Option.ID_donthuoc > 0) { Option.Date_Edited = DateTime.Now; _donthuocService.Update(Option); } else { Option.Date_Created = DateTime.Now; Option.ngayCapThuoc = DateTime.Now; _donthuocService.Create(Option); } } catch (Exception ex) { result.StatusCode = HttpStatusCode.InternalServerError; result.ReasonPhrase = ex.Message; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public bool Update(DonThuocEntities Option) { var success = false; if (Option != null) { using (var scope = new TransactionScope()) { var o = _unitOfWork.DonThuocRepository.Get(x => x.ID_donthuoc == Option.ID_donthuoc); if (o != null) { //o.ID_donDonThuoc = Option.ID_donDonThuoc; //o.tenDonThuoc = Option.tenDonThuoc; //o.loaiDonThuoc = Option.loaiDonThuoc; //o.soLuongTon = Option.soLuongTon; //o.GhiChu = Option.GhiChu; o.ID_donthuoc = Option.ID_donthuoc; o.ngayCapThuoc = Option.ngayCapThuoc; o.Date_Edited = DateTime.Now;; o.IsDelete = Option.IsDelete; } _unitOfWork.DonThuocRepository.Update(o); _unitOfWork.Save(); scope.Complete(); } } return(success); }
public int Create(DonThuocEntities Option) { using (var scope = new TransactionScope()) { Mapper.CreateMap <DonThuocEntities, DonThuoc>(); var o = Mapper.Map <DonThuocEntities, DonThuoc>(Option); o.IsDelete = false; o.Date_Created = DateTime.Now; _unitOfWork.DonThuocRepository.Insert(o); _unitOfWork.Save(); scope.Complete(); return(o.ID_donthuoc); } }