Ejemplo n.º 1
0
        public JsonResult CreateOrUpDate(CTHDEntities Option)
        {
            var result = new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK
            };

            try
            {
                if (Option.ID_HoaDon > 0 && Option.ID_Thuoc > 0)
                {
                    Option.Date_Edited = DateTime.Now;
                    _cthdService.Update(Option);
                }
                else
                {
                    Option.Date_Created = DateTime.Now;
                    _cthdService.Create(Option);
                }
            }
            catch (Exception ex)
            {
                result.StatusCode   = HttpStatusCode.InternalServerError;
                result.ReasonPhrase = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
 public CTHD Create(CTHDEntities Option)
 {
     using (var scope = new TransactionScope())
     {
         Mapper.CreateMap <CTHDEntities, CTHD>();
         var o = Mapper.Map <CTHDEntities, CTHD>(Option);
         o.IsDelete     = false;
         o.Date_Created = DateTime.Now;
         _unitOfWork.CTHDRepository.Insert(o);
         _unitOfWork.Save();
         scope.Complete();
         return(o);
     }
 }
Ejemplo n.º 3
0
        public bool Update(CTHDEntities Option)
        {
            var success = false;

            if (Option != null)
            {
                using (var scope = new TransactionScope())
                {
                    var o = _unitOfWork.CTHDRepository.Get(x => x.ID_HoaDon == Option.ID_HoaDon && x.ID_Thuoc == Option.ID_Thuoc);
                    if (o != null)
                    {
                        Mapper.CreateMap <CTHDEntities, CTHD>();
                        o = Mapper.Map <CTHDEntities, CTHD>(Option);
                    }
                    _unitOfWork.CTHDRepository.Update(o);
                    _unitOfWork.Save();
                    scope.Complete();
                }
            }
            return(success);
        }