示例#1
0
        public ActionResult Edit([Bind(Include = "CarSoldId,CarId,UserId,Email,PhoneNumber,AgreedPrice,Datesold,PaymentStatus,PaymentMethod,PaymentStartDate,PaymentEndDate,ActurePaymentAmount,OtherDetail")] CarSold carSold)
        {
            if (context.Cars.Find(carSold.CarId).Quantity == 0 || context.Cars.Find(carSold.CarId).Warranty == 0 || context.Cars.Find(carSold.CarId).Warranty == 2)
            {
                TempData["Msg"]       = "Out of Order";
                ViewBag.UserId        = new SelectList(context.Users, "Id", "UserName", carSold.UserId);
                ViewBag.CarId         = new SelectList(context.Cars, "CarId", "Name", carSold.CarId);
                ViewBag.PaymentStatus = new SelectList(Param._TransPayment, "Key", "Value", carSold.PaymentStatus);
                return(View(carSold));
            }



            if (ModelState.IsValid)
            {
                context.Entry(carSold).State = EntityState.Modified;

                if (carSold.PaymentStatus == 3 && context.CarSolds.Single(c => c.CarSoldId == carSold.CarSoldId).PaymentStatus != 3)
                {
                    context.Cars.Single(c => c.CarId == carSold.CarId).Quantity++;

                    //context.Entry(oc).State = EntityState.Modified;
                    // context.SaveChanges();
                }

                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CarId         = new SelectList(context.Cars, "CarId", "Name", carSold.CarId);
            ViewBag.PaymentStatus = new SelectList(Param._TransPayment, "Key", "Value");
            ViewBag.UserId        = new SelectList(context.Users, "Id", "UserName", carSold.UserId);
            return(View(carSold));
        }
示例#2
0
        public ActionResult Delete(long id)
        {
            CarSold carSold = context.CarSolds.Find(id);

            context.CarSolds.Remove(carSold);
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
        // GET: CarSolds/Delete/5
        public ActionResult Delete(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarSold carSold = context.CarSolds.Find(id);

            if (carSold == null)
            {
                return(HttpNotFound());
            }
            return(View(carSold));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "CarSoldId,CarId,UserId,Name,Email,PhoneNumber,AgreedPrice,Datesold,PaymentStatus,PaymentMethod,PaymentStartDate,PaymentEndDate,ActurePaymentAmount,OtherDetail")] CarSold carSold)
        {
            if (!string.IsNullOrEmpty(carSold.UserId))
            {
                if (string.IsNullOrEmpty(context.Users.Find(carSold.UserId).PhoneNumber))
                {
                    TempData["Msg"]       = "Customer Doesnt Have PhoneNumber";
                    ViewBag.CarId         = new SelectList(context.Cars, "CarId", "Name", carSold.CarId);
                    ViewBag.UserId        = new SelectList(context.Users, "Id", "UserName", carSold.UserId);
                    ViewBag.PaymentStatus = new SelectList(Param._TransPayment, "Key", "Value", carSold.PaymentStatus);
                    return(View(carSold));
                }
                carSold.PhoneNumber = context.Users.Find(carSold.UserId).PhoneNumber;
                carSold.Email       = context.Users.Find(carSold.UserId).Email;
                carSold.Name        = context.Users.Find(carSold.UserId).UserName;
            }
            else if (string.IsNullOrEmpty(carSold.UserId) && (string.IsNullOrEmpty(carSold.Name) ||
                                                              string.IsNullOrEmpty(carSold.Email) ||
                                                              string.IsNullOrEmpty(carSold.PhoneNumber)))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            if (context.Cars.Find(carSold.CarId).Quantity == 0 || context.Cars.Find(carSold.CarId).Warranty == 0 || context.Cars.Find(carSold.CarId).Warranty == 2)
            {
                TempData["Msg"]       = "Out of Order";
                ViewBag.CarId         = new SelectList(context.Cars, "CarId", "Name", carSold.CarId);
                ViewBag.UserId        = new SelectList(context.Users, "Id", "UserName", carSold.UserId);
                ViewBag.PaymentStatus = new SelectList(Param._TransPayment, "Key", "Value", carSold.PaymentStatus);
                return(View(carSold));
            }

            if (ModelState.IsValid)
            {
                context.CarSolds.Add(carSold);
                Car c = context.Cars.Find(carSold.CarId);
                c.Quantity--;
                context.Entry(c).State = EntityState.Modified;
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CarId = new SelectList(context.Cars, "CarId", "Name", carSold.CarId);
            return(View(carSold));
        }
示例#5
0
        // GET: CarSolds/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CarSold carSold = context.CarSolds.Find(id);

            if (carSold == null)
            {
                return(HttpNotFound());
            }


            ViewBag.PaymentStatus = new SelectList(Param._TransPayment, "Key", "Value", carSold.PaymentStatus);
            ViewBag.CarId         = new SelectList(context.Cars, "CarId", "Name", carSold.CarId);
            ViewBag.UserId        = new SelectList(context.Users, "Id", "UserName", carSold.UserId);
            return(View(carSold));
        }