Ejemplo n.º 1
0
        public Task <Unit> Handle(CreateShipmentCommand request, CancellationToken cancellationToken)
        {
            _shipmentService.CreateShipment(new Data.DbModels.Shipment()
            {
                DeliveryDate = request.DeliveryDate,
                Departure    = request.Departure,
                Destination  = request.Destination,
                Orders       = request.Orders,
                ShipmentDate = request.ShipmentDate,
            });

            return(Task.FromResult(Unit.Value));
        }
        public async Task <IActionResult> Post([FromBody] ShipmentForm model)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await _workContext.GetCurrentUser();

                var shipment = new Shipment
                {
                    OrderId        = model.OrderId,
                    WarehouseId    = model.WarehouseId,
                    CreatedById    = currentUser.Id,
                    TrackingNumber = model.TrackingNumber,
                    CreatedOn      = DateTimeOffset.Now,
                    UpdatedOn      = DateTimeOffset.Now
                };

                if (!User.IsInRole("admin"))
                {
                    shipment.VendorId = currentUser.VendorId;
                }

                foreach (var item in model.Items)
                {
                    if (item.QuantityToShip <= 0)
                    {
                        continue;
                    }

                    var shipmentItem = new ShipmentItem
                    {
                        Shipment    = shipment,
                        Quantity    = item.QuantityToShip,
                        ProductId   = item.ProductId,
                        OrderItemId = item.OrderItemId
                    };

                    shipment.Items.Add(shipmentItem);
                }

                var result = await _shipmentService.CreateShipment(shipment);

                if (result.Success)
                {
                    return(CreatedAtAction(nameof(Get), new { id = shipment.Id }, null));
                }

                return(BadRequest(result.Error));
            }

            return(BadRequest(ModelState));
        }
Ejemplo n.º 3
0
        public ActionResult Create([FromBody] ShipmentViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var shipmentEntity = new ShipmentEntity
                    {
                        Title     = model.Title,
                        IdService = model.IdService
                    };

                    var createdEntity = _shipmentService.CreateShipment(shipmentEntity);

                    ViewBag.RegisteredUser = true;
                    return(RedirectToAction("Details", new { id = createdEntity.IdShipment }));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Nepavyko sukurti vartotojo!");
            }
            return(View(model));
        }