public JsonResult CreateOrUpDate(GiaTriMacDinhEntities Option) { var result = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; try { if (Option.ID_GiaTri > 0) { Option.Date_Edited = DateTime.Now; _gtmdService.Update(Option); } else { Option.Date_Created = DateTime.Now; _gtmdService.Create(Option); } } catch (Exception ex) { result.StatusCode = HttpStatusCode.InternalServerError; result.ReasonPhrase = ex.Message; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public int Create(GiaTriMacDinhEntities Option) { using (var scope = new TransactionScope()) { Mapper.CreateMap <GiaTriMacDinhEntities, GiaTriMacDinh>(); var o = Mapper.Map <GiaTriMacDinhEntities, GiaTriMacDinh>(Option); o.IsDelete = false; o.Date_Created = DateTime.Now; _unitOfWork.GiaTriMacDinhRepository.Insert(o); _unitOfWork.Save(); scope.Complete(); return(o.ID_GiaTri); } }
public bool Update(GiaTriMacDinhEntities Option) { var success = false; if (Option != null) { using (var scope = new TransactionScope()) { var o = _unitOfWork.GiaTriMacDinhRepository.Get(x => x.ID_GiaTri == Option.ID_GiaTri); if (o != null) { o.ID_GiaTri = Option.ID_GiaTri; o.GiaTri = Option.GiaTri; o.ID_DinhNghiaGiaTri = Option.ID_DinhNghiaGiaTri; o.Date_Edited = DateTime.Now;; o.IsDelete = Option.IsDelete; } _unitOfWork.GiaTriMacDinhRepository.Update(o); _unitOfWork.Save(); scope.Complete(); } } return(success); }