Exemple #1
0
 public ActionResult Edit([Bind(Include = "ServiceDeskRequestID,RequestID")] ServiceDeskRequestEditViewModel sdrEdit)
 {
     if (ModelState.IsValid)
     {
         ServiceDeskRequest sdr = db.ServiceDeskRequests.Find(sdrEdit.ServiceDeskRequestID);
         sdr.ServiceDeskRequestID = sdrEdit.ServiceDeskRequestID;
         if (sdr.Request != null)
         {
             // Remove ServiceDesk Request from it's old Request's list
             sdr.Request.ServiceDeskRequests.Remove(sdr);
         }
         // Get the new request
         sdr.Request = db.Requests.Find(sdrEdit.RequestID);
         // Add ServiceDesk Request to new Request's list
         sdr.Request.ServiceDeskRequests.Add(sdr);
         db.Entry(sdr).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
             TempData["SuccessOHMsg"] = "ServiceDesk Request " + sdrEdit.ServiceDeskRequestID + " edited";
             return(RedirectToAction("Index"));
         }
         catch
         {
             TempData["DangerOHMsg"] = "Problem editing the ServiceDesk Request " + sdrEdit.ServiceDeskRequestID;
             return(RedirectToAction("Index"));
         }
     }
     ViewBag.RequestID = new SelectList(db.Requests, "RequestID", "RequestID", sdrEdit.ServiceDeskRequestID);
     return(View(sdrEdit));
 }
Exemple #2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ServiceDeskRequest ServiceDeskRequest = db.ServiceDeskRequests.Find(id);

            if (ServiceDeskRequest == null)
            {
                return(HttpNotFound());
            }
            ServiceDeskRequestEditViewModel sdrEdit = new ServiceDeskRequestEditViewModel();

            sdrEdit.ServiceDeskRequestID = ServiceDeskRequest.ServiceDeskRequestID;
            if (ServiceDeskRequest.Request != null)
            {
                sdrEdit.RequestID = ServiceDeskRequest.Request.RequestID;
            }
            ViewBag.RequestList = new SelectList(db.Requests.OrderBy(x => x.RequestID), "RequestID", "RequestID");
            return(View(sdrEdit));
        }