コード例 #1
0
        public ServiceRequestBase EditServiceRequest(ServiceRequestBase newItem)
        {
            var fetchedObject = ds.ServiceRequest.Find(newItem.Id);

            if (fetchedObject == null)
            {
                return null;
            }
            else
            {
                DateTime dateCreateFromDatabase = fetchedObject.dateLogged;
                newItem.dateUpdated = DateTime.Now;
                newItem.dateLogged = dateCreateFromDatabase;
                ds.Entry(fetchedObject).CurrentValues.SetValues(newItem);
                ds.SaveChanges();

                // Prepare and return the object. The automapper will also map the datelogged property (which we don't want)
                ServiceRequestBase serviceRequestbase = Mapper.Map<ServiceRequestBase>(fetchedObject);

                //replace the dateLogged back to original
                serviceRequestbase.dateLogged = dateCreateFromDatabase;

                return serviceRequestbase;
            }
        }
コード例 #2
0
        public ActionResult Create(AddServiceRequest newItem)
        {
            var sr = new ServiceRequestBase();
            ProgramManager pm = new ProgramManager();
            StudentManager sm = new StudentManager();

            if (ModelState.IsValid)
            {
                //Student Number does not exisit in the database
                if ( sm.getStudentByStudentNumber(newItem.studentNumber) == 0)
                {
                    ViewBag.StudentInvalidErrorMessage = "*Student Number does not exisit in the system";

                    var addForm = Mapper.Map<ServiceRequestAddForm>(newItem);
                    addForm.program = new SelectList(pm.getAllPrograms(), "Id", "programCode");

                    return View(addForm);
                }

                var addetItem = m.AddNewServiceRequest(newItem);

                if (addetItem == null)
                {
                    return RedirectToAction("index");
                }
                else
                {
                    return RedirectToAction("confirm");
                }
            }
            else
            {
                var addForm = Mapper.Map<ServiceRequestAddForm>(newItem);
                addForm.program = new SelectList(pm.getAllPrograms(), "Id", "programCode");

                return View(addForm);
            }
        }
コード例 #3
0
        public ServiceRequestBase GetServiceRequestById(int id)
        {
            var fetchedObject = ds.ServiceRequest.Include("Student").Include("Program").SingleOrDefault(i => i.Id == id);
            ServiceRequestBase s = new ServiceRequestBase();

            if (fetchedObject != null)
            {

                var serviceRequestBase = Mapper.Map<ServiceRequestBase>(fetchedObject);

                serviceRequestBase.studentNumber = fetchedObject.student.studentNumber;
                serviceRequestBase.ServiceTitle = fetchedObject.Title;
                serviceRequestBase.StudentName = fetchedObject.student.firstName + "," + fetchedObject.student.lastName;
                serviceRequestBase.ProgramCode = fetchedObject.program.programCode;
                serviceRequestBase.description = removeHtmlTags(fetchedObject.description);
                serviceRequestBase.notes = removeHtmlTags(fetchedObject.notes);

                return serviceRequestBase;
            }
            else
            {
                return null;
            }
        }
コード例 #4
0
        public ActionResult Edit(int id, ServiceRequestBase newItem)
        {
            if (ModelState.IsValid & id == newItem.Id)
            {
                // Attempt to update the item
                ServiceRequestBase editedItem = m.EditServiceRequest(newItem);

                if (editedItem == null)
                {
                    // There was a problem updating the object
                    return View(newItem);
                }
                else
                {
                    //item was edited
                    TempData["statusMessage"] = "Edits have been saved.";
                    return RedirectToAction("details", new { id = editedItem.Id });
                }
            }
            else
            {
                // Return the object so the user can edit it correctly
                return View(newItem);
            }
        }