Exemplo n.º 1
0
 public void ChangeState(string Id, string OrderId)
 {
     if (this.Session["Account"] == null)
     {
          Redirect("/Login");
     }
     int Sid = Convert.ToInt32(Id);
     int Oid = Convert.ToInt32(OrderId);
     Order changeOrder = new Order();
     Order newOrder = new Order();
     changeOrder = db.Orders.Find(Oid);
     newOrder.Name = changeOrder.Name;
     newOrder.Note = changeOrder.Note;
     newOrder.TotalCash = changeOrder.TotalCash;
     newOrder.DateInfo = DateTime.Now;
     newOrder.Deadline = changeOrder.Deadline;
     newOrder.State = Sid;
     newOrder.CreaterId = changeOrder.CreaterId;
     newOrder.CustomerId = changeOrder.CustomerId;
     newOrder.Invisible = false;
     changeOrder.Invisible = true;
     db.Orders.Add(newOrder);
      db.SaveChanges();
 }
Exemplo n.º 2
0
 public ActionResult Create(Order order, string cusId)
 {
     if (this.Session["Account"] == null)
     {
         return Redirect("/Login");
     }
     var id = Convert.ToInt32(cusId);
     IFormatProvider culture = new CultureInfo("vi-VN", true);
     IList<Order> list = this.listOrder;
     if (ModelState.IsValid) {
         order.CustomerId = id;
         order.DateInfo = DateTime.Now;
         order.CreaterId = Convert.ToInt32(this.Session["ID"]);
         order.State = 1;
         order.Invisible = false;
         if (order.DateInfo < order.Deadline)
         {
             db.Orders.Add(order);
             if (order.DateStart != null) {
                 Process schedule = new Process();
                 schedule.OrderId = order.Id;
                 db.Processes.Add(schedule);
             }
             db.SaveChanges();
             return RedirectToAction("Index");
         }
         else { ViewBag.Error = "Hạn giao phải lớn hơn hôm nay!"; }
     }
     list = db.Orders.Where(s => s.CustomerId == id && s.Invisible == false).OrderBy(s => s.Deadline).ToPagedList(1, defaultPageSize);
     ViewBag.listOrder = list;
     Customer cus = db.Customers.Find(id);
     ViewBag.customer = cus;
     return View();
 }
Exemplo n.º 3
0
        public ActionResult Edit(Order order)
        {
            if (this.Session["Account"] == null)
            {

                return Redirect("/Login");
            }
            if (ModelState.IsValid)
            {
                if (order.DateInfo < order.Deadline)
                {
                    db.Entry(order).State = EntityState.Modified;
                    if (order.DateStart != null)
                    {
                        var schedule = db.Processes.Where(s => s.OrderId == order.Id).FirstOrDefault();
                        if (schedule == null)
                        {
                            schedule.OrderId = order.Id;
                            db.Processes.Add(schedule);
                        }
                        db.SaveChanges();
                        return RedirectToAction("Index");
                    }
                }
                    else { ViewBag.Error = "Hạn giao phải lớn hơn hôm nay!"; }
                }
                ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", order.CustomerId);
                ViewBag.CreaterId = new SelectList(db.Staffs, "Id", "StaffName", order.CreaterId);
                return View(order);
        }