Example #1
0
        public ActionResult AddCustomer(tbl_Customers model)
        {
            tbl_Customers obj = new tbl_Customers();

            obj.CustomerID = model.CustomerID;
            obj.FirstName  = model.FirstName;
            obj.Surname    = model.Surname;
            obj.Phone      = model.Phone;
            obj.Email      = model.Email;

            dbObj.tbl_Customers.Add(obj);
            try
            {
                dbObj.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }
            return(View("Customer"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            tbl_Customers tbl_Customers = db.tbl_Customers.Find(id);

            db.tbl_Customers.Remove(tbl_Customers);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Customers tbl_Customers = db.tbl_Customers.Find(id);

            if (tbl_Customers == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_Customers));
        }
        //[ActionAuthorizeAttribute("BaoGia")]
        public ActionResult DetailCustomers(int id)
        {
            tbl_Customers tblCustomers = db.tbl_Customers.Find(id);

            if ((string)Session["ck"] == "1")
            {
                ViewBag.thongbao = "Khách hàng có đơn hàng không được xóa";
                Session["ck"]    = "0";
            }
            else
            {
                ViewBag.thongbao = "";
            }
            return(View("DetailCustomers", tblCustomers));
        }
 public ActionResult Edit([Bind(Include = "IDCustomers,NameCustomers,ChucvuCustomers,CongTyCustomers,CodeCustomers,EmailCustomers,PhoneCustomers,FaxCustomers,DiaChiCustomers,MasothueCustomers,StatusCustomers,CreateDateCustomers,ModifyDateCustomers,CreateUserCustomers,ModifyUserCustomers,NoteCustomer")] tbl_Customers tbl_Customers)
 {
     if (ModelState.IsValid)
     {
         var listCus = from a in db.tbl_Customers where a.CodeCustomers == tbl_Customers.CodeCustomers && a.IDCustomers != tbl_Customers.IDCustomers select a;
         if (listCus.ToList().Count == 0)
         {
             db.Entry(tbl_Customers).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewData["mess"] = "Mã khách hàng đã tồn tại";
     }
     return(View(tbl_Customers));
 }
        public ActionResult Delete(int?id)
        {
            var qr = from datadh in db.tbl_OrderTem
                     where datadh.customer_id == id
                     select datadh;

            if (qr.ToList().Count > 0)
            {
                Session["ck"] = "1";

                return(RedirectToAction("DetailCustomers", new { id }));
            }
            else
            {
                tbl_Customers tbl_Customers = db.tbl_Customers.Find(id);
                db.tbl_Customers.Remove(tbl_Customers);
                db.SaveChanges();
                Session["ck"] = "0";
            }

            return(RedirectToAction("Index"));
        }
Example #7
0
        public ActionResult OrderComplete(string name, string address, string email, string phone, string cardid)
        {
            tbl_Customers cus = db.tbl_Customers.Where(a => a.Email == email || a.Phone == phone).FirstOrDefault();

            if (cus == null)
            {
                cus = new tbl_Customers();
                cus.CustomerName = name;
                cus.Address      = address;
                cus.Email        = email;
                cus.Phone        = phone;
                cus.CardID       = cardid;

                db.tbl_Customers.Add(cus);
                db.SaveChanges();
            }

            tbl_Orders order = new tbl_Orders();

            order.CustomerID = cus.CustomerID;
            order.CreateDate = DateTime.Now;
            order.Status     = laca.Models.OrderStatus.Order;
            db.tbl_Orders.Add(order);
            db.SaveChanges();

            List <tbl_OrderDetail> list = Session[Session.SessionID] as List <tbl_OrderDetail>;

            foreach (var item in list)
            {
                item.tbl_Items = null;
                item.OrderID   = order.OrderID;
                db.tbl_OrderDetail.Add(item);
                db.SaveChanges();
            }

            return(Json(new { url = Url.Action("ThankYou", new { id = order.OrderID }) }));
            //return View();
        }