/// <summary>
        /// Queries all order requests
        /// Allows for selection of requests to be ordered
        /// </summary>
        /// <returns></returns>
        public ActionResult PartRequest()
        {
            var suppliers        = _context.StockRoomSuppliers.ToList();
            var requests         = _context.StockroomRequestLines.Where(x => x.StockRoomRequest.StockRoomRequestStatusId == 0).Include(x => x.ManufacturerPart).ToList();
            var indexes          = _context.StockroomSupplierPartIndexes;
            var requestSuppliers = new List <RequestSuppliersViewModel>();

            foreach (var request in requests)
            {
                RequestSuppliersViewModel rs = new RequestSuppliersViewModel();
                if (request.ManufacturerPartId >= 6)
                {
                    var supplierId = indexes.FirstOrDefault(x => x.ManufacturerPartId == request.ManufacturerPartId).StockRoomSupplierId;
                    rs.Supplier = _context.StockRoomSuppliers.FirstOrDefault(x => x.Id == supplierId);
                    rs.Quantity = _context.StockRoomInventories.FirstOrDefault(x => x.ManufacturerPartId == request.ManufacturerPartId).OnHand;
                    rs.Request  = request;

                    requestSuppliers.Add(rs);
                }
            }
            PartRequestViewModel viewModel = new PartRequestViewModel()
            {
                Suppliers       = suppliers,
                RequestSupplier = requestSuppliers
            };

            return(View(viewModel));
        }
 public IHttpActionResult SubmitPartDetails(PartRequestViewModel model)
 {
     using (UKPartsDBEntities db = new UKPartsDBEntities())
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest("Posted invalid data."));
         }
         if (model != null)
         {
             try
             {
                 var config = new MapperConfiguration(cfg =>
                 {
                     cfg.CreateMap <PartRequestViewModel, PartRequestDetail>();
                 });
                 IMapper mapper      = config.CreateMapper();
                 var     partDetails = mapper.Map <PartRequestDetail>(model);
                 partDetails.Id          = Guid.NewGuid().ToString();
                 partDetails.RequestedOn = DateTime.Now;
                 db.PartRequestDetails.Add(partDetails);
                 db.SaveChanges();
                 return(Ok(new ResponseModel {
                     Message = "Part request submitted successfully.", Status = "Success"
                 }));
             }
             catch (Exception ex)
             {
                 return(Ok(new ResponseModel {
                     Message = ex.Message, Status = "Fail"
                 }));
             }
         }
         return(Ok());
     }
 }