Exemple #1
0
        public ActionResult Edit([Bind(Include = "DN_ID,TTDH_ID,KH_ID,HTTT_ID,DN_NGALAPDON,DN_GHICHU,DN_SDT,DN_EMAIL,DN_DIACHI,DN_MATHE,DN_CHUTHE,DN_NGAYCAP")] DONHANG dONHANG)
        {
            Mail mail    = new Mail();
            var  CTSP_ID = (from p in db.CHITIETDONHANGs where p.DN_ID == dONHANG.DN_ID select p);
            CHITIETDONHANGsController cHITIETDONHANGs = new CHITIETDONHANGsController();

            if (dONHANG != null)
            {
                if (Convert.ToInt16(dONHANG.TTDH_ID) == 2)
                {
                    foreach (var i in CTSP_ID)
                    {
                        CHITIETSANPHAM cHITIETSANPHAM = db.CHITIETSANPHAMs.FirstOrDefault(sp => sp.CTSP_ID == i.CTSP_ID);
                        cHITIETDONHANGs.EditHuy(cHITIETSANPHAM.CTSP_ID);
                    }
                    string guimail = mail.SendMailFull("*****@*****.**", "vinhvavinh", "SMTP.gmail.com", "587", dONHANG.DN_EMAIL, "Đã hủy đơn hàng", "Đơn hàng " + dONHANG.DN_ID + " đã bị hủy .", true);
                }
                else if (Convert.ToInt16(dONHANG.TTDH_ID) == 1)
                {
                    string guimail = mail.SendMailFull("*****@*****.**", "vinhvavinh", "SMTP.gmail.com", "587", dONHANG.DN_EMAIL, "Đã duyệt đơn hàng", "Đơn hàng " + dONHANG.DN_ID + " đã được duyệt thành công", true);
                }
                else if (Convert.ToInt16(dONHANG.TTDH_ID) == 3)
                {
                    string guimail = mail.SendMailFull("*****@*****.**", "vinhvavinh", "SMTP.gmail.com", "587", dONHANG.DN_EMAIL, "Đã giao thành công", "Đơn hàng " + dONHANG.DN_ID + " đã được giao thành công", true);
                }

                dONHANG.NV_ID   = Session["NV_ID"].ToString();
                dONHANG.TTDH_ID = dONHANG.TTDH_ID;
                if (ModelState.IsValid)
                {
                    db.Entry(dONHANG).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(dONHANG));
            }

            //if (ModelState.IsValid)
            //{
            //if (Convert.ToInt16(id_ttdh) == 2)
            //{
            //    EditHuy(id_dh);
            //}
            //    dONHANG.NV_ID = Session["NV_ID"].ToString();
            //    db.Entry(dONHANG).State = EntityState.Modified;
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}
            ViewBag.HTTT_ID = new SelectList(db.HINHTHUCTHANHTOANs, "HTTT_ID", "HTTT_TEN", dONHANG.HTTT_ID);
            ViewBag.KH_ID   = new SelectList(db.KHACHHANGs, "KH_ID", "KH_TEN", dONHANG.KH_ID);
            ViewBag.TTDH_ID = new SelectList(db.TRANGTHAIDONHANGs, "TTDH_ID", "TTDH_TEN", dONHANG.TTDH_ID);
            return(View(dONHANG));
        }
Exemple #2
0
        public JsonResult EditDuyet(int id)
        {
            DONHANG dONHANG = db.DONHANGs.FirstOrDefault(m => m.DN_ID == id);
            var     SP_ID   = (from p in db.CHITIETDONHANGs where p.DN_ID == id select p);
            CHITIETDONHANGsController cHITIETDONHANGs = new CHITIETDONHANGsController();

            if (dONHANG != null)
            {
                foreach (var i in SP_ID)
                {
                    SANPHAM sANPHAM = db.SANPHAMs.FirstOrDefault(sp => sp.SP_ID == i.CTSP_ID);
                    cHITIETDONHANGs.EditHuy(sANPHAM.SP_ID);
                }
                dONHANG.TTDH_ID = 2;
                db.SaveChanges();
            }
            string a = "Đã hũy đơn hàng " + id;

            return(Json(a, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        public JsonResult EditHuy(int id)
        {
            Mail    mail    = new Mail();
            DONHANG dONHANG = db.DONHANGs.FirstOrDefault(m => m.DN_ID == id);
            var     SP_ID   = (from p in db.CHITIETDONHANGs where p.DN_ID == id select p);
            CHITIETDONHANGsController cHITIETDONHANGs = new CHITIETDONHANGsController();

            if (dONHANG != null)
            {
                foreach (var i in SP_ID)
                {
                    CHITIETSANPHAM cHITIETSANPHAM = db.CHITIETSANPHAMs.FirstOrDefault(sp => sp.CTSP_ID == i.CTSP_ID);
                    cHITIETDONHANGs.EditHuy(cHITIETSANPHAM.SP_ID);
                }
                dONHANG.TTDH_ID = 2;
                string guimail = mail.SendMailFull("*****@*****.**", "vinhvavinh", "SMTP.gmail.com", "587", Session["KH_EMAIL"].ToString(), "Đã hủy đơn hàng", "Đơn hàng " + dONHANG.DN_ID + " đã bị hủy .", true);
                db.SaveChanges();
            }
            string a = "Đã hũy đơn hàng " + id;

            return(Json(a, JsonRequestBehavior.AllowGet));
        }