예제 #1
0
        public async Task <ActionResult> EditShipment(ShipmentViewModel model)
        {
            using (var context = new ShoppingCartContext())
            {
                //new item
                if (model.Id == 0)
                {
                    var shipment = new Shipment
                    {
                        Code      = model.Code,
                        Recipient = model.Recipient,
                        ShipDate  = DateTime.Parse(model.ShipDate),
                    };

                    context.Shipments.Add(shipment);
                    await context.SaveChangesAsync();

                    var orderLists = model.OrderIdsString.Split(',');

                    context.Orders.Where(o => orderLists.Contains(o.OrderNumber.ToString())).ForEach(order =>
                    {
                        order.ShipmentId = shipment.Id;
                    });
                }

                await context.SaveChangesAsync();
            }
            return(View());
        }
예제 #2
0
        public ActionResult ViewShipment(string code)
        {
            using (var context = new ShoppingCartContext())
            {
                var shipment = context.Shipments.SingleOrDefault(s => s.Code.Equals(code));

                var ret = new ShipmentViewModel();
                ret.Orders    = new List <ShipmentOrderViewModel>();
                ret.ShipDate  = "";
                ret.Recipient = "";

                if (shipment != null)
                {
                    ret.ShipDate  = shipment.ShipDate.ToShortDateString();
                    ret.Recipient = shipment.Recipient;
                    ret.Code      = shipment.Code;

                    context.Orders.Where(o => o.ShipmentId == shipment.Id).ForEach(or =>
                                                                                   ret.Orders.Add(new ShipmentOrderViewModel()
                    {
                        CustomerName = or.FullName,
                        OrderNumber  = or.OrderNumber,
                        OrderTotal   = or.Total,
                        Id           = or.Id
                    }));
                }
                return(View(ret));
            }
        }
        public static ShipmentViewModel ConvertToShipmentViewModelLite(this Shipment shipment)
        {
            ShipmentViewModel shipmentViewModel = new ShipmentViewModel()
            {
                Id         = shipment.Id,
                Identifier = shipment.Identifier,

                Code           = shipment.Code,
                ShipmentDate   = shipment.ShipmentDate,
                Address        = shipment.Address,
                ShipmentNumber = shipment.ShipmentNumber,
                Acceptor       = shipment.Acceptor,
                DeliveryDate   = shipment.DeliveryDate,
                ReturnReceipt  = shipment.ReturnReceipt,
                DocumentName   = shipment.DocumentName,
                Note           = shipment.Note,

                IsActive = shipment.Active,

                UpdatedAt = shipment.UpdatedAt,
                CreatedAt = shipment.CreatedAt
            };


            return(shipmentViewModel);
        }
예제 #4
0
        private static ShipmentViewModel Read(SqliteDataReader query)
        {
            int counter = 0;
            ShipmentViewModel dbEntry = new ShipmentViewModel();

            dbEntry.Id              = SQLiteHelper.GetInt(query, ref counter);
            dbEntry.Identifier      = SQLiteHelper.GetGuid(query, ref counter);
            dbEntry.Code            = SQLiteHelper.GetString(query, ref counter);
            dbEntry.ShipmentDate    = SQLiteHelper.GetDateTime(query, ref counter);
            dbEntry.Address         = SQLiteHelper.GetString(query, ref counter);
            dbEntry.ServiceDelivery = SQLiteHelper.GetServiceDelivery(query, ref counter);
            dbEntry.ShipmentNumber  = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Acceptor        = SQLiteHelper.GetString(query, ref counter);
            dbEntry.DeliveryDate    = SQLiteHelper.GetDateTime(query, ref counter);
            dbEntry.ReturnReceipt   = SQLiteHelper.GetString(query, ref counter);
            dbEntry.DocumentName    = SQLiteHelper.GetString(query, ref counter);
            dbEntry.Note            = SQLiteHelper.GetString(query, ref counter);

            dbEntry.IsSynced = SQLiteHelper.GetBoolean(query, ref counter);

            dbEntry.UpdatedAt = SQLiteHelper.GetDateTime(query, ref counter);
            dbEntry.CreatedBy = SQLiteHelper.GetCreatedBy(query, ref counter);
            dbEntry.Company   = SQLiteHelper.GetCompany(query, ref counter);
            return(dbEntry);
        }
예제 #5
0
        public ActionResult ShipmentDetails(Guid shipment_id)
        {
            Shipment          shipment  = new Shipment();
            ShipmentViewModel viewModel = new ShipmentViewModel();

            BindDropDownValues();

            shipment = context.Shipments.ToList().Where(x => x.ShipmentId == shipment_id).FirstOrDefault();

            if (shipment != null)
            {
                viewModel = BindValues(shipment);
            }
            else
            {
                viewModel = new ShipmentViewModel();
            }

            ViewData.Model = viewModel;

            if (Request.IsAjaxRequest())
            {
                return(PartialView());
            }

            return(View());
        }
예제 #6
0
        public ShipmentResponse Create(ShipmentViewModel Shipment)
        {
            ShipmentResponse response = new ShipmentResponse();

            using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db"))
            {
                db.Open();
                SqliteCommand insertCommand = db.CreateCommand();
                insertCommand.CommandText = SqlCommandInsertPart;

                try
                {
                    insertCommand = AddCreateParameters(insertCommand, Shipment);
                    insertCommand.ExecuteNonQuery();
                }
                catch (SqliteException error)
                {
                    MainWindow.ErrorMessage = error.Message;
                    response.Success        = false;
                    response.Message        = error.Message;
                    return(response);
                }
                db.Close();

                response.Success = true;
                return(response);
            }
        }
예제 #7
0
        public bool Create(ShipmentViewModel model, IDataSourceError error)
        {
            if (this.CurrentUser.IsInRole("Company"))
            {
                error.Error.AppendLine("公司端不可新增");
                return(false);
            }

            var shipment = new Shipment
            {
                UserId     = this.CurrentUserId,
                UserRoleId = this.userService.GetRoleByUser(this.CurrentUserId),
                Date       = model.Date
            };

            if (model.Customer != null && !string.IsNullOrEmpty(model.Customer.Value))
            {
                shipment.CustomerId     = Convert.ToInt32(model.Customer.Value);
                shipment.CustomerRoleId = this.userService.GetRoleByCustomer(shipment.CustomerId.Value);
            }

            this.DbContext.Shipments.Add(shipment);
            var result = false;

            try
            {
                this.DbContext.SaveChanges();
                model.ShipmentId = shipment.ShipmentId;
                result           = true;
            }
            catch { }

            return(result);
        }
예제 #8
0
        public ActionResult shipment(ShipmentViewModel shipmentViewModel)
        {
            CartWrapper cart = new CartWrapper();

            cart = (CartWrapper)Session["AddToCart"];
            Order order = new Order()
            {
                First_Name      = shipmentViewModel.First_Name,
                Last_Name       = shipmentViewModel.Last_Name,
                MobileNumber    = shipmentViewModel.MobileNumber,
                ShippingAddress = shipmentViewModel.ShippingAddress,
                CityId          = Convert.ToInt32(shipmentViewModel.SelectedCity),
                OrderDate       = DateTime.Now,
                TaxAmount       = cart.Tax,
                TotalAmount     = cart.Total,
                SubTotal        = cart.SubTotal,
                UserId          = shipmentViewModel?.UserId,
                OrderStatusId   = 1,
                OrderDetails    = OrderDetails(cart)
            };
            Order orderNo = _unitOfWork.Order.Add(order);

            _unitOfWork.Complete();
            _unitOfWork.Dispose();
            Session["AddToCart"] = null;
            return(RedirectToAction("Invoice", orderNo));
        }
예제 #9
0
        private ShipmentViewModel BindValues(Shipment shipment)
        {
            ShipmentViewModel viewModel = new ShipmentViewModel();

            List <Country> countries = new List <Country>();
            List <City>    cities    = new List <City>();

            countries = context.Countries.ToList();
            cities    = context.Cities.ToList();

            viewModel.ShipmentId            = shipment.ShipmentId;
            viewModel.ShipmentNo            = shipment.ShipmentNo;
            viewModel.ShipmentStatus        = shipment.ShipmentStatus.ToString();
            viewModel.ShipmentCurrentCityId = shipment.ShipmentCurrentCityId;
            viewModel.ShipmentCurrentCity   = cities.Where(x => x.CityId == shipment.ShipmentCurrentCityId).FirstOrDefault().CityName;
            viewModel.ShippingMethod        = shipment.ShippingMethod;
            viewModel.SenderCountryId       = shipment.SenderCountryId;
            viewModel.SenderCountry         = countries.Where(x => x.CountryId == shipment.SenderCountryId).FirstOrDefault().CountryName;
            viewModel.SenderCityId          = shipment.SenderCityId;
            viewModel.SenderCity            = cities.Where(x => x.CityId == shipment.SenderCityId).FirstOrDefault().CityName;
            viewModel.DestinationCountryId  = shipment.DestinationCountryId;
            viewModel.DestinationCountry    = countries.Where(x => x.CountryId == shipment.DestinationCountryId).FirstOrDefault().CountryName;
            viewModel.DestinationCityId     = shipment.DestinationCityId;
            viewModel.DestinationCity       = cities.Where(x => x.CityId == shipment.DestinationCityId).FirstOrDefault().CityName;
            viewModel.ShipmentRouteId       = shipment.ShipmentRouteId;
            viewModel.ShipmentRouteIndex    = shipment.ShipmentRouteIndex;

            return(viewModel);
        }
        public virtual IEnumerable <ShipmentViewModel> CreateShipmentsViewModel(ICart cart)
        {
            foreach (var shipment in cart.GetFirstForm().Shipments)
            {
                var shipmentModel = new ShipmentViewModel
                {
                    ShipmentId      = shipment.ShipmentId,
                    CartItems       = new List <CartItemViewModel>(),
                    Address         = _addressBookService.ConvertToModel(shipment.ShippingAddress),
                    ShippingMethods = CreateShippingMethodViewModels(cart.Market, cart.Currency, shipment)
                };

                shipmentModel.ShippingMethodId = shipment.ShippingMethodId == Guid.Empty ? shipmentModel.ShippingMethods.First().Id : shipment.ShippingMethodId;

                var variants = _contentLoader.GetItems(shipment.LineItems.Select(x => _referenceConverter.GetContentLink(x.Code)),
                                                       _preferredCulture).OfType <VariationContent>();

                foreach (var lineItem in shipment.LineItems)
                {
                    var variant = variants.Single(x => x.Code == lineItem.Code);

                    var productLink = variant.GetParentProducts(_relationRepository).FirstOrDefault();
                    if (ContentReference.IsNullOrEmpty(productLink))
                    {
                        continue;
                    }

                    shipmentModel.CartItems.Add(_cartItemViewModelFactory.CreateCartItemViewModel(cart, lineItem, variant));
                }

                yield return(shipmentModel);
            }
        }
예제 #11
0
        public async Task <IActionResult> UpdateShipmentsAsync(ShipmentViewModel shipmentViewModel)
        {
            var shipmentDto = _mapper.Map <ShipmentDto>(shipmentViewModel);
            await _orderService.UpdateShipmentDetailsAsync(shipmentDto);

            return(RedirectToAction(nameof(ListAsync)));
        }
        public virtual IEnumerable <ShipmentViewModel> CreateShipmentsViewModel(ICart cart)
        {
            foreach (var shipment in cart.GetFirstForm().Shipments)
            {
                var shipmentModel = new ShipmentViewModel
                {
                    ShipmentId      = shipment.ShipmentId,
                    CartItems       = new List <CartItemViewModel>(),
                    Address         = _addressBookService.ConvertToModel(shipment.ShippingAddress),
                    ShippingMethods = CreateShippingMethodViewModels(cart.MarketId, cart.Currency, shipment)
                };

                shipmentModel.ShippingMethodId = shipment.ShippingMethodId == Guid.Empty && shipmentModel.ShippingMethods.Any() ?
                                                 shipmentModel.ShippingMethods.First().Id
                                               : shipment.ShippingMethodId;

                var entries = _catalogContentService.GetItems <EntryContentBase>(shipment.LineItems.Select(x => x.Code));

                foreach (var lineItem in shipment.LineItems)
                {
                    var entry = entries.FirstOrDefault(x => x.Code == lineItem.Code);
                    if (entry == null)
                    {
                        //Entry was deleted, skip processing.
                        continue;
                    }

                    shipmentModel.CartItems.Add(_cartItemViewModelFactory.CreateCartItemViewModel(cart, lineItem, entry));
                }

                yield return(shipmentModel);
            }
        }
예제 #13
0
        public string UpdateDeliveryStatus(ShipmentViewModel shipmentViewModelObj)
        {
            OperationsStatusViewModel OperationsStatusViewModelObj = null;

            try
            {
                shipmentViewModelObj.log             = new LogDetailsViewModel();
                shipmentViewModelObj.log.UpdatedBy   = _commonBusiness.GetUA().UserName;
                shipmentViewModelObj.log.UpdatedDate = _commonBusiness.GetCurrentDateTime();
                OperationsStatusViewModelObj         = Mapper.Map <OperationsStatus, OperationsStatusViewModel>(_shipmentBusiness.UpdateDeliveryStatus(Mapper.Map <ShipmentViewModel, Shipment>(shipmentViewModelObj)));

                if (OperationsStatusViewModelObj.StatusCode == 1)
                {
                    return(JsonConvert.SerializeObject(new { Result = "OK", Record = OperationsStatusViewModelObj }));
                }
                else
                {
                    return(JsonConvert.SerializeObject(new { Result = "Error", Record = OperationsStatusViewModelObj }));
                }
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(new { Result = "", Message = ex.Message }));
            }
        }
예제 #14
0
        public async Task <IActionResult> SetShipmentOptionsAsync(ShipmentViewModel shipmentViewModel)
        {
            var shipmentDto = _mapper.Map <ShipmentDto>(shipmentViewModel);
            await _orderService.SetShipmentDetailsAsync(shipmentDto);

            return(RedirectToAction(nameof(IndexAsync)));
        }
예제 #15
0
        // GET: Services/Details/170e4cee-5335-4edf-aa33-663127c93200
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var shipmentEntity = _shipmentService.GetSingle((Guid)id);

            if (shipmentEntity == null)
            {
                return(HttpNotFound());
            }

            var serviceViewModel = new ShipmentViewModel
            {
                IdService    = shipmentEntity.IdService,
                Title        = shipmentEntity.Title,
                IdShipment   = shipmentEntity.IdShipment,
                Status       = shipmentEntity.Status,
                Created      = shipmentEntity.CreatedDate,
                LastUpdate   = shipmentEntity.UpdatedDate,
                Latitude     = shipmentEntity.Latitude,
                Longitude    = shipmentEntity.Longitude,
                StartTime    = shipmentEntity.StartTime,
                EndTime      = shipmentEntity.StartTime,
                Transactions = _transactionService.GetList(shipmentEntity.IdShipment)
            };

            return(View(serviceViewModel));
        }
        public static Shipment ConvertToShipment(this ShipmentViewModel shipmentViewModel)
        {
            Shipment shipment = new Shipment()
            {
                Id         = shipmentViewModel.Id,
                Identifier = shipmentViewModel.Identifier,

                Code           = shipmentViewModel.Code,
                ShipmentDate   = shipmentViewModel.ShipmentDate,
                Address        = shipmentViewModel.Address,
                ShipmentNumber = shipmentViewModel.ShipmentNumber,
                Acceptor       = shipmentViewModel.Acceptor,
                DeliveryDate   = shipmentViewModel.DeliveryDate,
                ReturnReceipt  = shipmentViewModel.ReturnReceipt,
                DocumentName   = shipmentViewModel.DocumentName,
                Note           = shipmentViewModel.Note,

                ServiceDeliveryId = shipmentViewModel.ServiceDelivery?.Id ?? null,

                Active = shipmentViewModel.IsActive,

                CreatedById = shipmentViewModel.CreatedBy?.Id ?? null,
                CompanyId   = shipmentViewModel.Company?.Id ?? null,

                CreatedAt = shipmentViewModel.CreatedAt,
                UpdatedAt = shipmentViewModel.UpdatedAt
            };

            return(shipment);
        }
예제 #17
0
        private SqliteCommand AddCreateParameters(SqliteCommand insertCommand, ShipmentViewModel Shipment)
        {
            insertCommand.Parameters.AddWithValue("@ServerId", Shipment.Id);
            insertCommand.Parameters.AddWithValue("@Identifier", Shipment.Identifier);
            insertCommand.Parameters.AddWithValue("@Code", ((object)Shipment.Code) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ShipmentDate", ((object)Shipment.ShipmentDate) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Address", ((object)Shipment.Address) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ServiceDeliveryId", ((object)Shipment.ServiceDelivery?.Id) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ServiceDeliveryIdentifier", ((object)Shipment.ServiceDelivery?.Identifier) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ServiceDeliveryCode", ((object)Shipment.ServiceDelivery?.Code) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ServiceDeliveryName", ((object)Shipment.ServiceDelivery?.Name) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ServiceDeliveryURL", ((object)Shipment.ServiceDelivery?.URL) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ShipmentNumber", ((object)Shipment.ShipmentNumber) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Acceptor", ((object)Shipment.Acceptor) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@DeliveryDate", ((object)Shipment.DeliveryDate) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@ReturnReceipt", ((object)Shipment.ReturnReceipt) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@DocumentName", ((object)Shipment.DocumentName) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@Note", ((object)Shipment.Note) ?? DBNull.Value);

            insertCommand.Parameters.AddWithValue("@IsSynced", Shipment.IsSynced);
            insertCommand.Parameters.AddWithValue("@UpdatedAt", ((object)Shipment.UpdatedAt) ?? DBNull.Value);
            insertCommand.Parameters.AddWithValue("@CreatedById", MainWindow.CurrentUser.Id);
            insertCommand.Parameters.AddWithValue("@CreatedByName", MainWindow.CurrentUser.FirstName + " " + MainWindow.CurrentUser.LastName);
            insertCommand.Parameters.AddWithValue("@CompanyId", MainWindow.CurrentCompany.Id);
            insertCommand.Parameters.AddWithValue("@CompanyName", MainWindow.CurrentCompany.CompanyName);

            return(insertCommand);
        }
예제 #18
0
        public bool?Update(int key, ShipmentViewModel model, IDataSourceError error)
        {
            var shipment = this.SingleOrDefault(key);

            if (shipment == null)
            {
                return(null);
            }

            if (model.Customer != null && !string.IsNullOrEmpty(model.Customer.Value))
            {
                shipment.CustomerId     = Convert.ToInt32(model.Customer.Value);
                shipment.CustomerRoleId = this.userService.GetRoleByCustomer(shipment.CustomerId.Value);
            }
            else
            {
                shipment.CustomerId = null;
            }

            shipment.Date = model.Date;

            //this.shipmentDetailService.RefreshShipment(shipment);
            bool result = false;

            try
            {
                this.DbContext.SaveChanges();
                result = true;
            }
            catch { }

            return(result);
        }
예제 #19
0
        public async Task <ActionResult> Index(Guid id, ShipmentViewModel model)
        {
            var data = mapper.Map <Shipment>(model, id);

            await mediator.SendAsync(new SetDraftData <Shipment>(id, data));

            return(RedirectToAction("Index", "WasteOperation", new { id }));
        }
예제 #20
0
        public void UpdateShipmentsAsync_CallsService_Always()
        {
            var viewModel = new ShipmentViewModel();

            _orderController.UpdateShipmentsAsync(viewModel);

            A.CallTo(() => _orderService.UpdateShipmentDetailsAsync(A <ShipmentDto> ._)).MustHaveHappenedOnceExactly();
        }
예제 #21
0
        public async Task <ActionResult> Index(Guid id)
        {
            var data = await mediator.SendAsync(new GetDraftData <Shipment>(id));

            var model = new ShipmentViewModel(data);

            return(View(model));
        }
예제 #22
0
        public IActionResult Update([FromBody] CrudViewModel <ShipmentViewModel> payload)
        {
            ShipmentViewModel value = payload.value;
            var result = _functionalService
                         .Update <ShipmentViewModel, Shipment>(value, Convert.ToInt32(value.ShipmentId));

            return(Ok());
        }
예제 #23
0
        public async Task <IActionResult> Calculate(string ShipmentId)
        {
            Shipment currShipment = this.offersService.GetShipmentById(ShipmentId);

            ShipmentViewModel offerForShipment = await this.offersService.GetOffer(currShipment);

            return(this.View(offerForShipment));
        }
        public ShipmentResponse Create(ShipmentViewModel re)
        {
            ShipmentResponse response = new ShipmentResponse();

            try
            {
                // Backup documents
                List <ShipmentDocumentViewModel> shipmentDocuments = re.ShipmentDocuments?.ToList();
                re.ShipmentDocuments = null;

                Shipment createdShipment = unitOfWork.GetShipmentRepository().Create(re.ConvertToShipment());



                // Update documents
                if (shipmentDocuments != null && shipmentDocuments.Count > 0)
                {
                    // Items for create or update
                    foreach (var shipmentDocument in shipmentDocuments
                             .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <ShipmentDocumentViewModel>())
                    {
                        shipmentDocument.Shipment = new ShipmentViewModel()
                        {
                            Id = createdShipment.Id
                        };
                        shipmentDocument.ItemStatus = ItemStatus.Submited;
                        ShipmentDocument createdShipmentDocument = unitOfWork.GetShipmentDocumentRepository()
                                                                   .Create(shipmentDocument.ConvertToShipmentDocument());
                    }

                    foreach (var item in shipmentDocuments
                             .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <ShipmentDocumentViewModel>())
                    {
                        item.Shipment = new ShipmentViewModel()
                        {
                            Id = createdShipment.Id
                        };
                        unitOfWork.GetShipmentDocumentRepository().Create(item.ConvertToShipmentDocument());

                        unitOfWork.GetShipmentDocumentRepository().Delete(item.Identifier);
                    }
                }

                unitOfWork.Save();

                response.Shipment = createdShipment.ConvertToShipmentViewModel();
                response.Success  = true;
            }
            catch (Exception ex)
            {
                response.Shipment = new ShipmentViewModel();
                response.Success  = false;
                response.Message  = ex.Message;
            }

            return(response);
        }
예제 #25
0
        /// <summary>
        /// convert shipment to view model
        /// </summary>
        /// <param name="shipment"></param>
        /// <returns></returns>
        public ShipmentViewModel ConvertToView(Shipment shipment)
        {
            ShipmentViewModel model = new ShipmentViewModel();

            var _vesselRepository = new VesselRepository();
            var _portRepository   = new PortRepository();
            var _bolRepository    = new BillOfLadingRepository();

            var vessel = _vesselRepository.GetVessel(shipment.VesselId);
            var port   = _portRepository.GetPort(shipment.PortId);
            var bols   = _bolRepository.GetBillOfLadings().Where(x => x.ShipmentId == shipment.ShipmentId).ToList();

            model.ShipmentId        = shipment.ShipmentId;
            model.CarrierId         = shipment.CarrierId;
            model.VesselId          = shipment.VesselId;
            model.PortId            = shipment.PortId;
            model.DepartureDate     = shipment.DepartureDate;
            model.EstArrivalDate    = (shipment.EstArrivalDate != null) ? shipment.EstArrivalDate : DateTime.MinValue;
            model.ShipmentNotes     = (!string.IsNullOrEmpty(shipment.Notes)) ? shipment.Notes : "N/A";
            model.VesselName        = (vessel != null && !string.IsNullOrEmpty(vessel.Name)) ? vessel.Name : "N/A";
            model.PortName          = (port != null && !string.IsNullOrEmpty(port.Name)) ? port.Name : "N/A";
            model.DepartureDateStr  = shipment.DepartureDate.ToShortDateString();
            model.EstArrivalDateStr = (shipment.EstArrivalDate != null) ? shipment.EstArrivalDate.Value.ToShortDateString() : "N/A";
            model.IsComplete        = shipment.IsComplete;
            model.CompletedDate     = (shipment.CompletedDate != null) ? shipment.CompletedDate : DateTime.MinValue;
            model.CompletedDateStr  = (shipment.CompletedDate != null) ? shipment.CompletedDate.Value.ToShortDateString() : "N/A";
            model.CreatedDate       = (shipment.CreatedDate != null) ? shipment.CreatedDate : DateTime.MinValue;

            if (bols != null && bols.Count > 0)
            {
                model.BillsOfLading = new List <BillOfLadingViewModel>();
                foreach (var bol in bols)
                {
                    BillOfLadingViewModel convertedModel = new BillOfLadingConverter().ConvertToView(bol);

                    model.BillsOfLading.Add(convertedModel);
                }
            }

            if (_vesselRepository != null)
            {
                _vesselRepository.Dispose();
                _vesselRepository = null;
            }
            if (_portRepository != null)
            {
                _portRepository.Dispose();
                _portRepository = null;
            }
            if (_bolRepository != null)
            {
                _bolRepository.Dispose();
                _bolRepository = null;
            }

            return(model);
        }
        public async Task <bool> AddShipment(ShipmentViewModel newShipment)
        {
            var entityShipment = new Shipment
            {
                Id          = new Guid(),
                Name        = newShipment.Name,
                Address     = newShipment.Address,
                Phone       = newShipment.Phone,
                IsDelivered = false,
                TotalCost   = (int)newShipment.TotalCost
            };

            _dbContex.Shipments.Add(entityShipment);

            foreach (OrderProductViewModel order in newShipment.OrderProduct)
            {
                var entity = new OrderedProduct
                {
                    Id         = new Guid(),
                    ProductID  = order.ProductID,
                    Quantity   = order.Quantity,
                    ShipmentId = entityShipment.Id
                };
                _dbContex.OrderedProducts.Add(entity);
            }
            var result = await _dbContex.SaveChangesAsync();

            var entityCount = newShipment.OrderProduct.Count + 1;

            if (result == entityCount)
            {
                try
                {
                    foreach (OrderProductViewModel order in newShipment.OrderProduct)
                    {
                        var contex = await _dbContex.Products.FindAsync(order.ProductID);

                        if (contex.InStock < order.Quantity)
                        {
                            contex.InStock = 0;
                        }
                        else
                        {
                            contex.InStock = (contex.InStock - order.Quantity);
                        }
                        _dbContex.SaveChanges();
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(false);
                }
            }
            return(false);
        }
        private static void OnCurrentShipmentPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            ShipmantPopup     popup    = source as ShipmantPopup;
            ShipmentViewModel Shipment = (ShipmentViewModel)e.NewValue;

            //popup.txtShipmant.Text = Shipment != null ? Shipment.Code.ToString() : "";
            //popup.txtShipmant.Text = Shipment != null ? Shipment.ShipmentDate.ToString() : "";
            //popup.txtShipmant.Text = Shipment != null ? Shipment.Address.ToString() : "";
            ////popup.txtShipmant.Text = Shipment != null ? Shipment.ServiceDelivery.Name.ToString() : "";
            popup.txtShipmant.Text = Shipment != null?Shipment.ShipmentNumber.ToString() : "";
        }
예제 #28
0
        public ActionResult UpdateInventory([FromBody] ShipmentViewModel shipment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var id         = shipment.ProductId;
            var adjustment = shipment.Adjustment;
            var inventory  = _inventoryService.UpdateAvailableQuantity(id, adjustment);

            return(Ok(inventory));
        }
예제 #29
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            ShipmentViewModel Shipment = new ShipmentViewModel();

            Shipment.Identifier   = Guid.NewGuid();
            Shipment.ShipmentDate = DateTime.Now;

            Shipment_AddEdit addEditForm = new Shipment_AddEdit(Shipment, true, false);

            addEditForm.ShipmentCreatedUpdated += new ShipmentHandler(SyncData);
            FlyoutHelper.OpenFlyout(this, ((string)Application.Current.FindResource("Pošiljke")), 95, addEditForm);
        }
예제 #30
0
        public async Task <IActionResult> Create(ShipmentViewModel shipment)
        {
            try
            {
                await _service.CreateAsync(_mapper.Map <ShipmentDTO>(shipment));

                return(Redirect($"/orders/details/{shipment.OrderId}"));
            }
            catch
            {
                return(BadRequest());
            }
        }