public ServiceRequestBase AddNewServiceRequest(AddServiceRequest newItem) { var program = ds.Program.Find(newItem.ProgramId); var student = ds.Student.Where(i => i.studentNumber == newItem.studentNumber).SingleOrDefault(); if (program != null && student != null) { var service = Mapper.Map<ServiceRequest>(newItem); //removes the html and other special tags and converts it to plain text service.description = removeHtmlTags(newItem.description); service.program = program; service.student = student; service.dateLogged = DateTime.Now; service.dateUpdated = DateTime.Now; service.Title = newItem.ServiceTitle; ds.ServiceRequest.Add(service); ds.SaveChanges(); return Mapper.Map<ServiceRequestBase>(service); } else { return null; } }
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); } }