Ejemplo n.º 1
0
        public ActionResult ScheduleRequest(SchedulePrdnJobViewModel newViewJob, IEnumerable<HttpPostedFileBase> uploadedFiles)
        {
            ProductionJob addedJob;

            //ModelState.AddModelError("", "Test Schedule Error");

            ActionUpdateResult result = AddNewJobFromViewModel(newViewJob, uploadedFiles, out addedJob, UpdateScheduledRequest);

            if (result.Type == ActionUpdateType.Success)
            {
                return RedirectToAction(actionName: "Jobs", controllerName: "Schedule",
                        routeValues: new
                        {
                            id = addedJob.RunID,
                            page = LastPageForRun(addedJob.RunID)
                        });
            }
            else if (result.Type == ActionUpdateType.Invalid)
            {
                return View(newViewJob);
            }
            else
            { //if (result ==  ActionSaveResult.Exception {
                return ErrMsgView("Error Saving Job");
            }
        }
Ejemplo n.º 2
0
        public ActionResult ScheduleRequest(string reqID, string urlReturn, int? runID)
        {
            // get Request
            var request = (from r in PrdnDBContext.Requests.Include("CstOrderLine").Include("Product").Include("Product.ProductType")
                           where r.ID == reqID
                           select r).FirstOrDefault();

            if (request == null)
            {
                return ErrMsgView("request ID '" + reqID + "' is not valid.");
            }
            else if ((request.Status != RequestStatus.NEW) && (request.Status != RequestStatus.PROCESSING))
            {
                return ErrMsgView("request ID '" + reqID + "' is not new or processing.");
            }

            if (runID == null)
            {
                UserSettingsViewModel settings = GetUserSettingsViewModel(true);
                runID = (int?)settings.IfNotNull(s => s.DefaultRunID);
            }

            CST.Prdn.Data.ProductionRun run = null;
            if (runID != null)  // is this run ID the correct product type?
            {
                run = (from r in PrdnDBContext.ProductionRuns
                       where r.ID == runID
                       select r)
                       .FirstOrDefault();
            }

            if ((run == null) || (run.PrdnType.ProdTypeCD != request.Product.ProdTypeCD))
            {
                RequestScheduleViewModel model = new RequestScheduleViewModel
                {
                    RequestID = reqID,
                    OrderNo = run.IfNotNull(r => r.PrdnOrderNo),
                    ProdTypeCD = request.Product.ProdTypeCD,
                    ProdTypeDescr = request.Product.ProductType.Description,
                    ProdCD = request.ProdCD,
                    ProdDescr = request.PartDescr,
                    UrlReturn = urlReturn
                };

                return RedirectToAction(actionName: "RequestRun", routeValues: model);
            }

            // job view model
            SchedulePrdnJobViewModel viewJob = new SchedulePrdnJobViewModel();

            viewJob.UrlReturn = urlReturn;
            //viewJob.LookupRunModel = new PrdnRunLookupModel();

            viewJob.loadFromRun(run);

            viewJob.CustID = PrdnDataHelper.PrdnCustIDCST;
            viewJob.PriorityID = PrdnDataHelper.PrdnPriorityIDDefault;

            if (viewJob.ProdTypeCD != request.Product.ProdTypeCD)
            {
                return ErrMsgView("Sorry - The Request product type (" + request.Product.ProdTypeCD +
                    ") does not match the target Runs's product type (" + viewJob.ProdTypeCD + ")");
            }

            viewJob.ProdCD = request.ProdCD;
            viewJob.ProdDescr = request.Product.Description;
            viewJob.ParentProdCD = request.Product.ParentProdCD;

            viewJob.CustLocation = request.RequestDeptID;
            viewJob.ShipMethodCD = request.ShipBranchVia;
            viewJob.PackingListNote = request.RequestComment;

            viewJob.CreatedUserLogin = GetCurrentUserLogin();

            viewJob.OrderNo = request.OrderNo;
            viewJob.OrderLine = request.OrderLine;
            viewJob.OrderLineID = request.CstOrderLine.IfNotNull(l => l.OrderLineID);

            viewJob.CstRequestID = request.ID;
            viewJob.SpecialWSDescr = request.SpecialWSDescr;

            loadJobViewForOrder(viewJob);
            LoadViewJobProdLists(viewJob);
            AssignViewJobLookupListsFuncs(viewJob);
            loadViewJobViewAttachments(viewJob, "A,S");

            viewJob.CustName = GetCustName(viewJob.CustID);
            viewJob.CustLocName = GetCustLocName(viewJob.CustID);

            if (viewJob.CstRequestID != null)
            {
                viewJob.EditWorksheet = new WorksheetEditViewModel(viewJob.ProdTypeCD) { Editable = false };
                viewJob.EditWorksheet.LoadFromRequest(viewJob.CstRequestID);
                overrideViewJobProdOpts(viewJob);

                var fileName = (from a in PrdnDBContext.RequestAttachments
                                where a.ID == viewJob.CstRequestID
                                select a.FileName).FirstOrDefault();

                viewJob.HasAttachment = (!String.IsNullOrEmpty(fileName));
            }

            viewJob.CanEditRun = true;
            return View(viewJob);
        }