Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,WorkOrderID,ColumnChanged,OldValue,NewValue,Timestamp")] WorkOrderHistory workOrderHistory)
        {
            if (id != workOrderHistory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(workOrderHistory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WorkOrderHistoryExists(workOrderHistory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["WorkOrderID"] = new SelectList(_context.WorkOrders, "WorkOrderID", "WorkOrderID", workOrderHistory.WorkOrderID);
            return(View(workOrderHistory));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,WorkOrderID,ColumnChanged,OldValue,NewValue,Timestamp")] WorkOrderHistory workOrderHistory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(workOrderHistory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["WorkOrderID"] = new SelectList(_context.WorkOrders, "WorkOrderID", "WorkOrderID", workOrderHistory.WorkOrderID);
            return(View(workOrderHistory));
        }
Esempio n. 3
0
        private void SeedWorkOrders(ApplicationDbContext context, int clientId, string userId, string createdByUserId)
        {
            for (int i = 0; i < 20; i++)
            {
                int    headOfficeLocationId;
                Random rnd = new Random();
                var    randomCustomerId = _clientCustomers[clientId].OrderBy(x => rnd.Next()).Take(1).FirstOrDefault();
                _customerHeadOffice.TryGetValue(randomCustomerId, out headOfficeLocationId);

                var workOrder = new WorkOrder()
                {
                    ClientId         = clientId,
                    CustomerId       = randomCustomerId,
                    LocationId       = headOfficeLocationId,
                    ProductId        = rnd.Next(1, 5),
                    Quantity         = $"{rnd.Next(1, 500)} L.",
                    CreatedByUserId  = createdByUserId,
                    CreatedDate      = DateTime.UtcNow,
                    AssignedToUserId = userId,
                    DueDate          = DateTime.UtcNow.AddDays(rnd.Next(1, 31)),
                    Notes            = $"Work order # {i}",
                    Status           = Status.Active,
                };

                context.WorkOrders.AddOrUpdate(workOrder);
                context.SaveChanges();

                var workOrderHistory = new WorkOrderHistory()
                {
                    WorkOrderId      = workOrder.Id,
                    ClientId         = clientId,
                    CustomerId       = randomCustomerId,
                    LocationId       = headOfficeLocationId,
                    ProductId        = rnd.Next(1, 5),
                    Quantity         = $"{rnd.Next(1, 500)} L.",
                    ModifiedByUserId = createdByUserId,
                    ModifiedDate     = DateTime.UtcNow,
                    AssignedToUserId = userId,
                    DueDate          = DateTime.UtcNow.AddDays(rnd.Next(1, 31)),
                    Status           = Status.Active,
                };

                context.WorkOrdersHistory.AddOrUpdate(workOrderHistory);
                context.SaveChanges();
            }
        }