public void GetNewRequisitionId_ExistingId_Valid()
        {
            // Arrange
            string expectedPrefix = $"REQ-{DateTime.Now.Year}{DateTime.Now.Month:00}";
            var    previous       = IdService.GetNewRequisitionId(context);

            new RequisitionRepository(context).Save(new Requisition()
            {
                RequisitionId   = previous,
                EmployeeRemarks = "IDSERVICETEST",
                CreatedDateTime = DateTime.Now.AddDays(1 - DateTime.Today.Day),
            });

            // Act
            var current = IdService.GetNewRequisitionId(context);

            new RequisitionRepository(context).Save(new Requisition()
            {
                RequisitionId   = current,
                EmployeeRemarks = "IDSERVICETEST",
                CreatedDateTime = DateTime.Now,
            });
            var previousSerialNoParseResult = Int32.TryParse(previous.Substring(previous.Length - 3), out int previousSerialNo);
            var resultSerialNoParseResult   = Int32.TryParse(current.Substring(current.Length - 3), out int resultSerialNo);

            // Assert
            Assert.AreEqual(1, resultSerialNo - previousSerialNo);
        }
        public void GetNewRequisitionIdTest()
        {
            // Arrange
            string expectedPrefix = $"REQ-{DateTime.Now.Year}{DateTime.Now.Month:00}";

            // Act
            var result = IdService.GetNewRequisitionId(context);
            var serialNoParseResult = Int32.TryParse(result.Substring(result.Length - 3), out int serialNo);

            // Assert
            Assert.AreEqual(expectedPrefix, result.Substring(0, 10));
            Assert.IsTrue(serialNoParseResult);
        }
        // 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"));
        }
Beispiel #4
0
        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));
        }