예제 #1
0
 public static int insert(phieuchi pt)
 {
     using (CTyPHSachEntities db = new CTyPHSachEntities())
     {
         var     tongtien     = db.ReceiptNotes.Find(pt.id_phieunhap).totalPrice;
         decimal tongthu      = 0;
         var     countphiethu = db.Payments.Where(x => x.ReceiptNoteID == pt.id_phieunhap).Count();
         if (countphiethu > 0)
         {
             tongthu = db.Payments.Where(x => x.ReceiptNoteID == pt.id_phieunhap).Select(y => y.price).Sum() + pt.thanhtoan;
         }
         if (tongtien < tongthu)
         {
             return(1);
         }
         else
         {
             var rs = Repostiory.insert(pt);
             if (rs)
             {
                 return(2);
             }
             else
             {
                 return(3);
             }
         }
     }
 }
 public ActionResult CreatePhieuthu(phieuchi pt)
 {
     if (Request.IsAjaxRequest())
     {
         var rq = PhieuChiService.insert(pt);
         return(Json(rq, JsonRequestBehavior.AllowGet));
     }
     return(View());
 }
예제 #3
0
 public bool insert(phieuchi pt)
 {
     using (CTyPHSachEntities db = new CTyPHSachEntities())
     {
         try
         {
             var entity = new Payments();
             entity.ReceiptNoteID = pt.id_phieunhap;
             entity.creatorName   = pt.nguoithu;
             entity.dateCreated   = pt.ngaylap;
             entity.price         = pt.thanhtoan;
             db.Payments.Add(entity);
             db.SaveChanges();
             return(true);
         }catch (Exception ex)
         {
             return(false);
         }
     }
 }