public async Task <IActionResult> CreateContainer(SRSObjectIndustrialContainerInputModel model, int id)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    model.ContainerItems = this.containerService.GetAllAsKeyValuePairs();
                    return(this.View(model));
                }

                if (model.ContainerId == 0)
                {
                    model.ContainerItems        = this.containerService.GetAllAsKeyValuePairs();
                    model.SrsobjectIndustrialId = id;
                    this.ModelState.AddModelError(string.Empty, "Please choose container!");
                    return(this.View(model));
                }

                var user = await this.userManager.GetUserAsync(this.User);

                await this.srsObjectIndustrialService.CreateContainersAsync(model, id, user.Id);

                this.TempData["Message"] = "Industrial container was added successfully.";

                return(this.RedirectToAction("AllContainers", new { id }));
            }
            catch (Exception ex)
            {
                model.ContainerItems = this.containerService.GetAllAsKeyValuePairs();
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View());
            }
        }
        public IActionResult CreateContainer(int id)
        {
            var model = new SRSObjectIndustrialContainerInputModel();

            model.ContainerItems        = this.containerService.GetAllAsKeyValuePairs();
            model.SrsobjectIndustrialId = id;
            return(this.View(model));
        }
Пример #3
0
        public async Task CreateContainersAsync(SRSObjectIndustrialContainerInputModel input, int id, string userId)
        {
            var lastContainerMovement = this.movementRepository.All()
                                        .FirstOrDefault(x => x.ContainerId == input.ContainerId && x.IsLastMovement == true);

            lastContainerMovement.IsLastMovement = false;
            await this.movementRepository.SaveChangesAsync();

            var srsObjectIndustrialId = this.warehousesRepository.All()
                                        .Where(x => x.Name == GlobalConstants.SRSObjectIndustrialName)
                                        .Select(x => x.Id)
                                        .FirstOrDefault();

            var movement = new Movement
            {
                ContainerId    = input.ContainerId,
                WarehouseId    = srsObjectIndustrialId,
                IsLastMovement = true,
                EntryDate      = DateTime.UtcNow,
                AddedByUserId  = userId,
            };

            await this.movementRepository.AddAsync(movement);

            await this.movementRepository.SaveChangesAsync();

            var movementId = movement.Id;

            var container = new SrsobjectIndustrialContainer
            {
                SrsobjectIndustrialId = id,
                ContainerId           = input.ContainerId,
                MovementId            = movementId,
                AddedByUserId         = userId,
            };

            await this.srsObjectIndurstiralContainerRepository.AddAsync(container);

            await this.srsObjectIndurstiralContainerRepository.SaveChangesAsync();
        }