public void FindByDepartmentTest() { // Arrange requisitionService.Save(new Requisition() { RequisitionId = "RQSERVTEST", Department = new DepartmentRepository(context).FindById("ENGL"), CreatedDateTime = DateTime.Now, }); // Act var result = requisitionService.FindRequisitionsByDepartment(new DepartmentRepository(context).FindById("ENGL")); // Assert result.ToList().ForEach(r => Assert.AreEqual("ENGL", r.Department.DepartmentCode)); }
// POST: /Requisition/Draft public ActionResult Draft(string rid) { ApplicationUser user = userRepository.FindById(User.Identity.GetUserId()); // for testing //ApplicationUser user = userRepository.FindById("446a381c-ff6c-4332-ba50-747af26d996e"); Requisition existingReq = requisitionRepository.FindById(rid); // create the requisition Requisition r = new Requisition(); r.RequisitionId = IdService.GetNewRequisitionId(context); r.RequisitionDetails = new List <RequisitionDetail>(); r.Status = statusService.FindStatusByStatusId(3); // create a draft r.CreatedDateTime = DateTime.Now; r.Department = user.Department; r.CollectionPoint = user.Department.CollectionPoint; r.CreatedBy = user; // create requisition details foreach (RequisitionDetail dd in existingReq.RequisitionDetails) { r.RequisitionDetails.Add(new RequisitionDetail { ItemCode = dd.ItemCode, Item = itemService.FindItemByItemCode(dd.ItemCode), Quantity = dd.Quantity, Status = statusService.FindStatusByStatusId(4) }); } try { requisitionService.Save(r); } catch { TempData["error"] = "error"; return(RedirectToAction("ManageRequisitions", "Requisition")); } TempData["draft"] = String.Format("Draft Requisition #{0} created.", r.RequisitionId); return(RedirectToAction("ManageRequisitions", "Requisition")); }
public IHttpActionResult CreateRequisition(UpdateRequisitionJSONViewModel json) { ApplicationUser user = userRepository.FindById(RequestContext.Principal.Identity.GetUserId()); // update the collection point Department d = departmentRepository.FindById(user.Department.DepartmentCode); d.CollectionPoint = collectionPointRepository.FindById(json.CollectionPointId); departmentRepository.Save(d); if (json.ItemList.Count < 1) { return(BadRequest("An unexpected error occured.")); } // create the requisition Requisition r = new Requisition(); r.RequisitionId = IdService.GetNewRequisitionId(context); r.RequisitionDetails = new List <RequisitionDetail>(); r.EmployeeRemarks = json.Remarks; if (json.IsDraft == true) { r.Status = statusService.FindStatusByStatusId(3); } else { r.Status = statusService.FindStatusByStatusId(4); } r.CreatedDateTime = DateTime.Now; r.Department = user.Department; r.CollectionPoint = collectionPointRepository.FindById(json.CollectionPointId); r.CreatedBy = user; // create requisition details foreach (UpdateRequisitionTableJSONViewModel dd in json.ItemList) { r.RequisitionDetails.Add(new RequisitionDetail { ItemCode = dd.ItemCode, Item = itemService.FindItemByItemCode(dd.ItemCode), Quantity = dd.Qty, Status = statusService.FindStatusByStatusId(4) }); } try { requisitionService.Save(r); } catch { return(BadRequest("An unexpected error occured.")); } // Create Notification Notification n = new NotificationService(context).CreateNotification(r, user.Department.Head); new NotificationApiController() { context = context }.SendNotification(n.NotificationId.ToString()); new NotificationApiController() { context = context }.SendEmail(n.NotificationId.ToString()); return(Ok(r.RequisitionId)); }