コード例 #1
0
ファイル: UserController.cs プロジェクト: GithubZD/BookStore
        public ActionResult EditUserInfo([Bind(Include = "UserId,Icon,LoginName,RealName,Password,CardNumber,Iphone,Age,Sex,Address,RoleId")] User user)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
コード例 #2
0
        public ActionResult AddOrder(int?carID, int?count, DateTime?date, int?useDay)
        {
            if (carID == null)
            {
                var result = new { Status = 0 };
                return(Json(result));
            }

            var car  = db.Cars.Find(carID);
            var user = db.Users.SingleOrDefault(u => u.LoginName == User.Identity.Name);

            if (car != null)
            {
                var newOrder = new Order
                {
                    UserId       = user.UserId,
                    OrderTime    = DateTime.Now,
                    PayYesNo     = 0,
                    Status       = 0,
                    Evaluate     = 0,
                    UserManager  = 1,
                    AdminManager = 1
                };
                db.Orders.Add(newOrder);
                int num = (int)count;
                if (car.NowNumber >= num)
                {
                    car.NowNumber = car.NowNumber - num;
                    var orderDetails = new OrderDetail
                    {
                        CarId    = (int)carID,
                        OrderId  = newOrder.OrderId,
                        AwayTime = (DateTime)date,
                        Days     = useDay,
                        Deposit  = useDay * num * car.RentPrice * (decimal)0.2,
                        Money    = useDay * num * car.RentPrice,
                        Number   = num,
                    };
                    db.OrderDetails.Add(orderDetails);
                    db.SaveChanges();

                    int id     = orderDetails.OrderDetailsId;
                    var result = new { Status = 1, id = id };
                    return(Json(result));
                }

                else
                {
                    var result = new { Status = 2 };
                    return(Json(result));
                }
            }
            else
            {
                var result = new { Status = 0 };
                return(Json(result));
            }
        }
コード例 #3
0
        // GET: MangerOrder/Create
        public ActionResult UserGetCar(int?OrderId)
        {
            if (OrderId == null)
            {
                var result = new
                {
                    State = 0
                };

                return(Json(result));
            }
            else
            {
                var order = db.Orders.SingleOrDefault(o => o.OrderId == OrderId);
                order.Status = 1;
                db.SaveChanges();
                var result = new
                {
                    State = 1
                };

                return(Json(result));
            }
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: GithubZD/BookStore
        public void CancelOrder()
        {
            DateTime nowDate    = DateTime.Now;
            var      rentOrders = db.OrderDetails.Where(o => o.Order.PayYesNo == 1).ToList();

            foreach (var item in rentOrders)
            {
                DateTime d1 = Convert.ToDateTime(nowDate);

                DateTime d2 = Convert.ToDateTime(item.AwayTime);

                DateTime d3 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d1.Year, d1.Month, d1.Day));

                DateTime d4 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d2.Year, d2.Month, d2.Day));

                int days = (d4 - d3).Days;
                if (days < 0)
                {
                    item.Order.PayYesNo = 2;
                    item.Order.Remark   = "订单逾期";
                }
                db.SaveChanges();
            }
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "CarId,CategroyId,SeatNumId,BrandId,CarName,PlateNumber,RentPrice,Number,Details")] Car car,
                                   HttpPostedFileBase imageFile)
        {
            if (ModelState.IsValid)
            {
                if (imageFile != null)
                {
                    string imageName = Guid.NewGuid().ToString() + imageFile.FileName;
                    string pathName  = Server.MapPath("~/Images/CarImg/" + imageName);
                    imageFile.SaveAs(pathName);
                    car.ImageUrl = "/Images/CarImg/" + imageName;
                    db.Cars.Add(car);
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.BrandId    = new SelectList(db.Brands, "BrandId", "BrandName", car.BrandId);
            ViewBag.CategroyId = new SelectList(db.Categroys, "CategoryId", "CategoryName", car.CategroyId);
            ViewBag.SeatNumId  = new SelectList(db.SeatNums, "SeatNumId", "SeatNumber", car.SeatNumId);
            return(View(car));
        }