示例#1
0
        //Inserts a new Staff Allocation
        public async Task <IActionResult> OnPostInsertStaffAlloc([FromBody] Models.ActCostSiloAllocation obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")))
            {
                try
                {
                    //Allocation Split is set to per Silo
                    obj.ActCostAllocationSplitID = 12;
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    int id = obj.ActCostSiloAllocationID; // Yes it's here
                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Staff Allocation Per Silo Not Added." + d.InnerException.Message));
                }
            }

            else
            {
                return(new JsonResult("Staff Allocation Per Silo Not Inserted"));
            }
        }
示例#2
0
        //Inserts a new Load with a Load Headers
        public async Task <IActionResult> OnPostInsertLoad([FromBody] Load obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")))
            {
                try
                {
                    //for a new Load the Load Status is always set as Incomplete
                    obj.LoadStatusID = 1;

                    obj.UserID     = _userManager.GetUserId(HttpContext.User);
                    obj.CreatedUtc = DateTime.Now;
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    int id = obj.LoadID; // Yes it's here
                    obj.User = await _userManager.GetUserAsync(HttpContext.User);

                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Load Not Added." + d.InnerException.Message));
                }
            }
            else
            {
                return(new JsonResult("Insert Load was null or you do not have access rights to change this load."));
            }
        }
示例#3
0
        //Inserts a new Vehicle with details
        public async Task <IActionResult> OnPostInsertVehicle([FromBody] Vehicle obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")))
            {
                try
                {
                    string regNo = obj.RegistrationNumber.ToString().Replace(" ", "").Trim();
                    regNo                        = regNo.ToString().Replace("-", "").Replace("/", "");
                    obj.RegNumberABB             = regNo;
                    obj.ActCostAllocationSplitID = _vehicleBusLayer.FindAllocationSplitID(obj.CostCentreID);
                    //enter CICOTI SubContractor Number
                    obj.SubContractorID = 2;
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    int id = obj.VehicleID; // Yes it's here
                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Vehicle Not Added." + d.InnerException.Message));
                }
            }

            else
            {
                return(new JsonResult("Insert Destination was null"));
            }
        }
示例#4
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"));
        }
示例#5
0
 /*      public async Task<IActionResult> OnPostAsync()
  *    {
  *        if (!ModelState.IsValid)
  *        {
  *            return Page();
  *        }
  *
  *        var EmptyLocation = new Location();
  *
  *        if (await TryUpdateModelAsync(
  *                 EmptyLocation,
  *                 "Location",
  *                  l => l.ProvinceID, l => l.LocationName,
  *                  l => l.GPSCoordinates, l=> l.Province.CountryID
  *                     ))
  *        {
  *            _context.Locations.Add(EmptyLocation);
  *            await _context.SaveChangesAsync();
  *            return RedirectToPage("./Index");
  *        }
  *        //Select Province ID if TryUpdateSync Fails
  *        PopulateCountryDropDownList(_context, EmptyLocation.Province.CountryID);
  *        PopulateProvinceDropDownList(_context, EmptyLocation.ProvinceID);
  *       return Page();
  *
  *    }
  *
  *    public async Task<IActionResult> OnPostAsyncLocation([FromBody] Location obj)
  *    {
  *        if (!ModelState.IsValid)
  *        {
  *            return new JsonResult("Location Data is incomplete or inaccurate");
  *        }
  *
  *        var EmptyLocation = new Location();
  *
  *        if (await TryUpdateModelAsync(
  *                 EmptyLocation,
  *                 "Location",
  *                  l => l.ProvinceID, l => l.LocationName,
  *                  l => l.GPSCoordinates
  *                     ))
  *        {
  *            _context.Locations.Add(EmptyLocation);
  *            await _context.SaveChangesAsync();
  *            return new JsonResult("New Location Added");
  *        }
  *
  *        return new JsonResult("Location Not Added");
  *
  *    }
  */
 public IActionResult OnPostInsert([FromBody] Location obj)
 {
     if (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin")))
     {
         _context.Add(obj);
         _context.SaveChanges();
         return(new JsonResult("Location: " + obj.LocationName + " added."));
     }
     return(new JsonResult("You do not have access to add Locations"));
 }
示例#6
0
        //Inserts a new Employee with details
        public async Task <IActionResult> OnPostInsertEmployee([FromBody] Models.Employee obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("HR")))
            {
                try
                {
                    obj.ActCostAllocationSplitID = _empBusLayer.FindAllocationSplitID(obj.CostCentreID, obj.DepartmentID);
                    if (obj.EmployeeID == 0)
                    {
                        _context.Add(obj);
                    }
                    else
                    {
                        _context.Attach(obj).State = EntityState.Modified;
                    }

                    await _context.SaveChangesAsync();

                    var value = new
                    {
                        msg      = "Employee Successfully Updated",
                        employee = obj
                    };
                    return(new JsonResult(value));
                }
                catch (DbUpdateException d)
                {
                    var value = new
                    {
                        msg      = "Employee Changes not Saved" + d.InnerException.Message,
                        employee = obj
                    };
                    return(new JsonResult(value));
                }
            }

            else
            {
                var value = new
                {
                    msg      = "Employee Changes not Saved",
                    employee = obj
                };
                return(new JsonResult(value));
            }
        }
示例#7
0
        public async Task <IActionResult> OnPostInsert([FromBody] StockCountItem obj)
        {
            if (obj != null)
            {
                try
                {
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    int id = obj.StockCountItemID; // Yes it's here
                    return(new JsonResult(id));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Stock Item Not Added." + d.InnerException.Message));
                }
            }
            else
            {
                return(new JsonResult("Stock Item not Loaded"));
            }
        }
示例#8
0
        public async Task <IActionResult> OnPostInsert([FromBody] Destination obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin"))))
            {
                try
                {
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    return(new JsonResult("Destination has been created successfully."));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("New Destination not created." + d.InnerException.Message));
                }
            }

            else
            {
                return(new JsonResult("Insert Destination was null"));
            }
        }
示例#9
0
        //Inserts a new Employee with details
        public async Task <IActionResult> OnPostInsertRepEmployeeLink([FromBody] SalesRepCodeEmployeeNoLink obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("HR")))
            {
                try
                {
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    int id = obj.SalesRepCodeEmployeeNoLinkID; // Yes it's here
                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Sales Rep Employee Not Added." + d.InnerException.Message));
                }
            }

            else
            {
                return(new JsonResult("Sales Rep Not Inserted"));
            }
        }
示例#10
0
        //Inserts a new Employee with details
        public async Task <IActionResult> OnPostInsertDriver([FromBody] Models.Driver obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")))
            {
                try
                {
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    int id = obj.DriverID; // Yes it's here
                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Driver Not Added." + d.InnerException.Message));
                }
            }

            else
            {
                return(new JsonResult("Driver Not Inserted"));
            }
        }