public void FindByIdTestNotNull()
        {
            // Act
            var result = collectionPointRepository.FindById(1);

            // Assert
            Assert.IsInstanceOfType(result, typeof(CollectionPoint));
        }
 public CollectionPoint FindCollectionPointById(int id)
 {
     return(collectionPointRepository.FindById(id));
 }
Пример #3
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));
        }