Пример #1
0
 public ActionResult Edit([Bind(Include = "Id,Text,Status,HistoryDateTime,RentRequestId")] RentRequestHistory rentrequesthistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rentrequesthistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RentRequestId = new SelectList(db.RentRequests, "Id", "FromPlace", rentrequesthistory.RentRequestId);
     return(View(rentrequesthistory));
 }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            RentRequestHistory rentrequesthistory = db.RentRequestHistorys.Find(id);

            if (rentrequesthistory != null)
            {
                db.RentRequestHistorys.Remove(rentrequesthistory);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Пример #3
0
        // GET: /RentRequestHistory/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentRequestHistory rentrequesthistory = db.RentRequestHistorys.Include(r => r.RentRequest).FirstOrDefault(m => m.Id == id);

            if (rentrequesthistory == null)
            {
                return(HttpNotFound());
            }
            return(View(rentrequesthistory));
        }
Пример #4
0
        // GET: /RentRequestHistory/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentRequestHistory rentrequesthistory = db.RentRequestHistorys.Find(id);

            if (rentrequesthistory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RentRequestId = new SelectList(db.RentRequests, "Id", "FromPlace", rentrequesthistory.RentRequestId);
            return(View(rentrequesthistory));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "Id,FromPlace,ToPlace,StartDateTime,EndDateTime,AirCondition,VehicleQty,Description,CustomerId,VehicleTypeId")] RentRequestViewModel rentRequestViewModel)
        {
            if (ModelState.IsValid)
            {
                var loginCustomerId = User.Identity.GetUserId();
                var customer        = db.Customers.FirstOrDefault(c => c.UserId == loginCustomerId);

                if (customer == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                RentRequest rentRequest = Mapper.Map <RentRequest>(rentRequestViewModel);
                rentRequest.CustomerId = customer.Id;
                db.RentRequests.Add(rentRequest);
                var isSave = db.SaveChanges() > 0;

                if (isSave)
                {
                    Notification notification = new Notification();
                    notification.Status              = "New";
                    notification.Details             = "New rent request ";
                    notification.NotificatinDateTime = DateTime.Now;
                    notification.CustomerId          = rentRequest.CustomerId;
                    notification.RentRequestId       = rentRequest.Id;
                    db.Notifications.Add(notification);
                    db.SaveChanges();

                    RentRequestHistory rentRequestHistory = new RentRequestHistory();
                    rentRequestHistory.Status          = "New";
                    rentRequestHistory.Text            = "New rent request";
                    rentRequestHistory.HistoryDateTime = DateTime.Now;
                    rentRequestHistory.RentRequestId   = rentRequest.Id;
                    db.RentRequestHistorys.Add(rentRequestHistory);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerId    = new SelectList(db.Customers, "Id", "Name", rentRequestViewModel.CustomerId);
            ViewBag.VehicleTypeId = new SelectList(db.VehicleTypes, "Id", "Name", rentRequestViewModel.VehicleTypeId);
            return(View(rentRequestViewModel));
        }