示例#1
0
        public async Task <JsonResult> OnPutUpdate([FromBody] List <InvoiceStatus> InvoiceListing)
        {
            int    NewInvoiceStatusID   = 0;
            string InvoiceNotAdded      = "WorkFlow Sequence Error: Invoices Not Added: ";
            int    InvProcessedCount    = 0;
            int    InvNotProcessedCount = 0;

            if (InvoiceListing != null && InvoiceListing.Count() > 0)
            {
                NewInvoiceStatusID = InvoiceListing.First().StatusID;
                //First Check if this user can update the Invoice to this Status
                if (await workFlowRule.WorkFlowRuleRole(NewInvoiceStatusID, HttpContext))
                {
                    try
                    {
                        var UserId = _userManager.GetUserId(HttpContext.User);
                        CicotiWebApp.Models.Invoice InvoiceItem;

                        //Update the Invoice Table in Database
                        foreach (var In in InvoiceListing)
                        {
                            InvoiceItem = _context.Invoices.FirstOrDefault(i => i.InvoiceID == In.InvoiceID);
                            if (workFlowRule.WorFlowRuleSequence(In.StatusID, InvoiceItem.StatusID))
                            {
                                In.UserID            = UserId;
                                InvoiceItem.StatusID = In.StatusID;
                                _context.Attach(InvoiceItem).State = EntityState.Modified;
                                _context.Add(In);
                                await _context.SaveChangesAsync();

                                InvProcessedCount += InvProcessedCount + 1;
                            }
                            else
                            {
                                InvNotProcessedCount += InvNotProcessedCount + 1;
                                InvoiceNotAdded      += InvoiceItem.InvoiceNumber + "; ";
                            }
                        }
                        if (InvNotProcessedCount == 0)
                        {
                            return(new JsonResult("Success: No of Invoices Processed: " + InvProcessedCount));
                        }
                        else
                        {
                            return(new JsonResult("No of Invoices Processed Successfully: " + InvProcessedCount + " . " + "No of Invoices Not Processed: " + InvNotProcessedCount + "; " + InvoiceNotAdded));
                        }
                    }
                    catch (DbUpdateException d)
                    {
                        return(new JsonResult("Invoice Status not Updated. " + d.InnerException.Message));
                    }
                }
                else
                {
                    return(new JsonResult("Invoice Status not Updated. You do not have rights to update to this Invoice Status."));
                }
            }//Nothing has been selected for updating
            return(new JsonResult("You have not selected Deliveries / Invoices for Updating"));
        }
示例#2
0
        //Add New Invoices to the Load Schedule
        public async Task <JsonResult> OnPostUpdate([FromBody] List <InvoiceStatus> InvoiceListing)
        {
            //Check if user can update this status to : Load Schedule
            if (InvoiceListing != null && await _workFlowRule.WorkFlowRuleRole(5, HttpContext))
            {
                try
                {
                    var UserId = _userManager.GetUserId(HttpContext.User);
                    CicotiWebApp.Models.Invoice InvoiceItem;

                    //Update the Invoice Table in Database
                    foreach (var In in InvoiceListing)
                    {
                        In.UserID   = UserId;
                        InvoiceItem = _context.Invoices.FirstOrDefault(i => i.InvoiceID == In.InvoiceID);
                        //Update to WH: Loading Schedule.
                        InvoiceItem.StatusID = 5;
                        In.StatusID          = 5;
                        //Add the Current Load Id to the Invoice
                        InvoiceItem.LoadID = In.LoadID;
                        _context.Attach(InvoiceItem).State = EntityState.Modified;
                        await _context.SaveChangesAsync();
                    }
                    //Update the InvoiceStatus Table in the Database
                    _context.InvoiceStatus.AddRange(InvoiceListing);
                    await _context.SaveChangesAsync();

                    return(new JsonResult("Invoice Status successfully"));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Invoice Status not Updated." + d.InnerException.Message));
                }
            }
            else
            {
                return(new JsonResult("Invoices not removed OR you do not have access to this functionality."));
            }
        }