Esempio n. 1
0
        public async Task <IActionResult> UpdateContainerStatus(int newStatusId, int containerId)
        {
            _context.ChangeTracker.LazyLoadingEnabled = false;

            var containerStatus = await _context.ContainerStatus.FindAsync(newStatusId);

            if (containerStatus == null)
            {
                return(NotFound("New status not found"));
            }

            var container = await _context.Containers.FindAsync(containerId);

            if (container == null)
            {
                return(NotFound("Container not found"));
            }

            container.StatusId = containerStatus.Id;

            _context.Update(container);
            await _context.SaveChangesAsync();

            _context.ChangeTracker.LazyLoadingEnabled = true;

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <ActionResult <ContainerComments> > DeleteContainerComments(int id)
        {
            var containerComments = await _context.ContainerComments.FindAsync(id);

            if (containerComments == null)
            {
                return(NotFound("Record not found, may have already been deleted. Try refreshing the page."));
            }

            _context.ContainerComments.Remove(containerComments);
            await _context.SaveChangesAsync();

            return(containerComments);
        }
Esempio n. 3
0
        public async Task <IActionResult> PostSuppliers([FromForm] Suppliers suppliers)
        {
            if (suppliers.Supplier == null)
            {
                return(BadRequest("No supplier name supplied"));
            }

            var supplierName      = suppliers.Supplier.Trim().ToLower();
            var duplicateSupplier = _context.Suppliers.Any(s => s.Supplier.Trim().ToLower() == supplierName);

            if (duplicateSupplier)
            {
                return(Conflict("This supplier is already saved. Please select it using the select list on the form."));
            }

            _context.Suppliers.Add(suppliers);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSuppliers", new { id = suppliers.Id }, suppliers));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create(CreateContainerViewModel containerVM)
        {
            if (ModelState.IsValid == false)
            {
                return(View(await CreateViewModelWithPopulatedFormInputs()));
            }

            int?itemD = null;

            if (containerVM.ExpNumOfUnits != null && containerVM.ActNumOfUnits != null)
            {
                itemD = containerVM.ExpNumOfUnits.Value - containerVM.ActNumOfUnits.Value;
            }

            var container = new Containers()
            {
                RefNum           = containerVM.RefNum,
                ExpTimeOfArrival = containerVM.ExpTimeOfArrival,
                ExpNumOfUnits    = containerVM.ExpNumOfUnits,
                ExpNumOfPallets  = containerVM.ExpNumOfPallets,
                ActTimeOfArrival = containerVM.ActTimeOfArrival,
                ActNumOfUnits    = containerVM.ActNumOfUnits,
                ActNumOfPallets  = containerVM.ActNumOfPallets,
                ArrivalDate      = DateTime.Today,
                DepartmentId     = containerVM.ContainerDepartmentId,
                TypeId           = containerVM.ContainerTypeId,
                BayId            = containerVM.BayId,
                DoorId           = containerVM.DoorId,
                StatusId         = containerVM.ContainerStatusId,
                ItemDiscrepancy  = (containerVM.ExpNumOfUnits.HasValue && containerVM.ActNumOfUnits.HasValue) ? (containerVM.ExpNumOfUnits.Value - containerVM.ActNumOfUnits.Value) : (int?)null
            };

            _context.Add(container);

            await _context.SaveChangesAsync();

            foreach (var comment in containerVM.Comments)
            {
                var containerComment = new ContainerComments()
                {
                    ContainerId = container.Id,
                    Comment     = comment.Comment
                };

                _context.Add(containerComment);
            }

            if (containerVM.SupplierIds?.Count() > 0)
            {
                foreach (var supplierId in containerVM.SupplierIds)
                {
                    var containerSuppliers = new ContainerSuppliers()
                    {
                        ContainerId = container.Id,
                        SupplierId  = supplierId.Value
                    };

                    _context.Add(containerSuppliers);
                }
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }