Exemplo n.º 1
0
        public static string Add(ShipmentDTO shipment)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                string   error       = null;
                Shipment newShipment = new Shipment();
                newShipment.Id               = shipment.Id;
                newShipment.ShippedItem      = shipment.ShippedItem;
                newShipment.ItemQuantity     = shipment.ItemQuantity;
                newShipment.RecipientCompany = shipment.RecipientCompany;
                newShipment.PostalCode       = shipment.PostalCode;
                newShipment.CityTown         = shipment.CityTown;
                newShipment.StreetAddress    = shipment.StreetAddress;
                newShipment.Weight           = shipment.Weight;
                newShipment.Description      = shipment.Description;

                var context = new ValidationContext(newShipment, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newShipment, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.Shipments.Add(newShipment);
                    db.SaveChanges();
                }
                return(error);
            }
        }
        public void Delete(ShipmentDTO client)
        {
            IWindowManager manager = new WindowManager();

            ShipmentService.Delete(client);
            Reload();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get a shipment by a certain ID.
        /// </summary>
        /// <param name="id">ID of the shipment to get.</param>
        /// <returns>Returns a shipment by a certain ID or an appropriate error message.</returns>
        public ShipmentDTO Get(int id)
        {
            var         shipment    = FindShipment(id);
            ShipmentDTO shipmentDTO = new ShipmentDTO(shipment);

            return(shipmentDTO);
        }
Exemplo n.º 4
0
        public void Return_Correct_Shipment()
        {
            var options   = Utils.GetOptions(nameof(Return_Correct_Shipment));
            var shipments = Utils.SeedShipments();

            using (var arrangeContext = new DeliverItContext(options))
            {
                arrangeContext.Shipments.AddRange(shipments);
                arrangeContext.Warehouses.AddRange(Utils.SeedWarehouses());
                arrangeContext.Statuses.AddRange(Utils.SeedStatuses());
                arrangeContext.Addresses.AddRange(Utils.SeedAddresses());
                arrangeContext.SaveChanges();
            }
            var shipmentDTO = new ShipmentDTO(shipments.First());

            using (var actContext = new DeliverItContext(options))
            {
                var sut    = new ShipmentService(actContext);
                var result = sut.Get(1);

                Assert.AreEqual(shipmentDTO.Id, result.Id);
                Assert.AreEqual(shipmentDTO.Status, result.Status);
                Assert.AreEqual(shipmentDTO.Warehouse, result.Warehouse);
                Assert.AreEqual(shipmentDTO.Departure, result.Departure);
                Assert.AreEqual(shipmentDTO.Arrival, result.Arrival);
            }
        }
 public void Add()
 {
     if (IsEdit == true)
     {
         toEdit.ShippedItem      = ShippedItem;
         toEdit.ItemQuantity     = ItemQuantity;
         toEdit.RecipientCompany = RecipientCompany;
         toEdit.CityTown         = CityTown;
         toEdit.PostalCode       = string.Format("{0}-{1}", PostalCode1, PostalCode2);
         toEdit.StreetAddress    = StreetAddress;
         toEdit.Weight           = Weight;
         toEdit.Description      = Description;
         ShipmentService.Edit(toEdit);
     }
     else
     {
         var newShipment = new ShipmentDTO();
         newShipment.ShippedItem      = ShippedItem;
         newShipment.ItemQuantity     = ItemQuantity;
         newShipment.RecipientCompany = RecipientCompany;
         newShipment.CityTown         = CityTown;
         newShipment.PostalCode       = string.Format("{0}-{1}", PostalCode1, PostalCode2);
         newShipment.StreetAddress    = StreetAddress;
         newShipment.Weight           = Weight;
         newShipment.Description      = Description;
         ShipmentService.Add(newShipment);
     }
     TryClose();
 }
Exemplo n.º 6
0
        private void ShowInventory_Clicked(object sender, EventArgs e)
        {
            //the  user has clicked on a line item shipment record from the top list
            //get the list of inventory items for the shipment that was clicked on

            Button button = sender as Button;

            if (button != null)
            {
                ShipmentDTO s = (ShipmentDTO)(button).CommandParameter;

                if (s != null)
                {
                    List <ShipmentInventoryMapDTO> inventory = shipmentList.Where(a => a.Shipment.ShipmentId == s.ShipmentId).Select(b => b.ShipmentInventoryMap).First();

                    ObservableCollection <ShipmentInventoryMapDTO> list1 = new ObservableCollection <ShipmentInventoryMapDTO>();

                    foreach (ShipmentInventoryMapDTO i in inventory)
                    {
                        list1.Add(i);
                    }

                    InventoryList.ItemsSource = list1;
                }
            }
        }
Exemplo n.º 7
0
        public static string Edit(ShipmentDTO shipment)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                string error = null;

                var toModify = db.Shipments.Where(x => x.Id == shipment.Id).FirstOrDefault();

                toModify.Id               = shipment.Id;
                toModify.ShippedItem      = shipment.ShippedItem;
                toModify.RecipientCompany = shipment.RecipientCompany;
                toModify.ItemQuantity     = shipment.ItemQuantity;
                toModify.PostalCode       = shipment.PostalCode;
                toModify.CityTown         = shipment.CityTown;
                toModify.StreetAddress    = shipment.StreetAddress;
                toModify.Weight           = shipment.Weight;
                toModify.Description      = shipment.Description;

                var context = new ValidationContext(toModify, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(toModify, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.SaveChanges();
                }
                return(error);
            }
        }
        public void LoadModifyShipmentPage(ShipmentDTO client)
        {
            IWindowManager       manager = new WindowManager();
            AddShipmentViewModel modify  = new AddShipmentViewModel(client);

            manager.ShowDialog(modify, null, null);
            Reload();
        }
Exemplo n.º 9
0
        public List <ShipmentDTO> GetBySelectedOrderIds(string orderIds)
        {
            var shipmentDTOs = new List <ShipmentDTO>();
            var shipmentDTO  = new ShipmentDTO {
                Orders = new List <ShipmentOrderDTO>()
            };
            var shipments         = _shipmentRepository.GetBySelectedOrderIds(orderIds);
            var currentAddress    = "";
            var currentCategoryId = 0;

            foreach (var shipment in shipments)
            {
                var currentOrder = new ShipmentOrderDTO
                {
                    OrderId            = Guid.NewGuid(),
                    Address            = shipment.Address,
                    City               = shipment.City,
                    State              = shipment.State,
                    Country            = shipment.Country,
                    FirstName          = shipment.FirstName,
                    LastName           = shipment.LastName,
                    ProductId          = shipment.ProductId,
                    ProductName        = shipment.ProductName,
                    ProductDescription = shipment.ProductDescription,
                    SKU          = shipment.ProductSKU,
                    Quantity     = shipment.Quantity,
                    Price        = string.Format("{0:0.00#}", shipment.Price),
                    Total        = string.Format("{0:0.00#}", shipment.Total),
                    CategoryId   = shipment.CategoryId,
                    CategoryName = shipment.CategoryName
                };

                if (shipment.Address != currentAddress || shipment.CategoryId != currentCategoryId)
                {
                    if (shipment != shipments.First())
                    {
                        shipmentDTOs.Add(shipmentDTO);
                        shipmentDTO = new ShipmentDTO {
                            Orders = new List <ShipmentOrderDTO>()
                        };
                    }
                    shipmentDTO.Orders.Add(currentOrder);
                    currentAddress    = shipment.Address;
                    currentCategoryId = shipment.CategoryId;
                }
                else
                {
                    shipmentDTO.Orders.Add(currentOrder);
                }

                if (shipment == shipments.Last())
                {
                    shipmentDTOs.Add(shipmentDTO);
                }
            }

            return(shipmentDTOs);
        }
Exemplo n.º 10
0
        public static void Delete(ShipmentDTO shipment)
        {
            using (WarehouseContext db = new WarehouseContext())
            {
                var toDelete = db.Shipments.Where(x => x.Id == shipment.Id).FirstOrDefault();
                toDelete.IsDisabled = true;

                db.SaveChanges();
            }
        }
Exemplo n.º 11
0
        public static ShipmentDB Cast(ShipmentDTO shipment)
        {
            var newObject = new ShipmentDB()
            {
                IdLoad            = shipment.IdLoad,
                Quantity          = shipment.Quantity,
                TotalWeigthOrders = shipment.TotalWeigthOrders,
                IdShipment        = shipment.IdShipment,
                Orders            = Cast(shipment.Orders)
            };

            return(newObject);
        }
        public List <ShipmentDTO> GetListShipment()
        {
            List <ShipmentDTO> listBillInfo = new List <ShipmentDTO>();

            DataTable data = ShipmentDAL.Instance.GetListShipment();

            foreach (DataRow item in data.Rows)
            {
                ShipmentDTO info = new ShipmentDTO(item);
                listBillInfo.Add(info);
            }
            return(listBillInfo);
        }
Exemplo n.º 13
0
        public async Task <int> CreateAsync(ShipmentDTO item)
        {
            item.DateTime = DateTime.Now;
            int shipmentId = await _repo.CreateAsync(_mapper.Map <Shipment>(item));

            var shipment = await ReadAsync(shipmentId);

            if (shipment.Order.UserId == item.RepicientApplicationUserId)
            {
                await _statusesService.SetDelivered(shipment.OrderId, null);
            }
            else if (shipment.Repicient.UserName.Contains("Courier", StringComparison.OrdinalIgnoreCase))
            {
                await _statusesService.SetByStatusString(shipment.OrderId, "Передан курьеру", null);
            }

            return(shipmentId);
        }
Exemplo n.º 14
0
        public static IList <ShipmentDTO> Cast(IEnumerable <ShipmentDB> orders)
        {
            var shipmentList = new List <ShipmentDTO>();

            foreach (var order in orders)
            {
                var newObject = new ShipmentDTO()
                {
                    IdShipment        = order.IdShipment,
                    Orders            = Cast(order.Orders),
                    Quantity          = order.Quantity,
                    TotalWeigthOrders = order.TotalWeigthOrders,
                    IdLoad            = order.IdLoad
                };
                shipmentList.Add(newObject);
            }

            return(shipmentList);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Filter shipments.
        /// </summary>
        /// <param name="filter">Filters for shipments.</param>
        /// <param name="value">Value of the filter</param>
        /// <returns>Returns the filtered shipments.</returns>
        public List <ShipmentDTO> GetBy(string filter, string value)
        {
            var allShipments = this.dbContext
                               .Shipments
                               .Include(s => s.Status)
                               .Include(s => s.Warehouse)
                               .ThenInclude(w => w.Address)
                               .Include(s => s.Parcels)
                               .ThenInclude(p => p.Customer);
            var shipments = new List <ShipmentDTO>();

            if (filter == "warehouse")
            {
                foreach (var shipment in allShipments)
                {
                    if ((shipment.WarehouseId == int.Parse(value)) && shipment.IsDeleted == false)
                    {
                        var shipmentDTO = new ShipmentDTO(shipment);
                        shipments.Add(shipmentDTO);
                    }
                }
            }

            if (filter == "customer")
            {
                foreach (var shipment in allShipments)
                {
                    if ((shipment.Parcels.Select(p => p.Customer)
                         .Where(c => c.FirstName.Equals(value, StringComparison.OrdinalIgnoreCase) || c.LastName.Equals(value, StringComparison.OrdinalIgnoreCase))
                         .Count() > 0) && shipment.IsDeleted == false)
                    {
                        var shipmentDTO = new ShipmentDTO(shipment);
                        shipments.Add(shipmentDTO);
                    }
                }
            }
            if (shipments.Count() == 0)
            {
                throw new ArgumentNullException(Exceptions.InvalidShipments);
            }
            return(shipments);
        }
Exemplo n.º 16
0
        public void AddShipment()
        {
            AddShipmentRequest addShipmentRequest = new AddShipmentRequest();

            ShipmentDTO dto = new ShipmentDTO()
            {
                VendorId     = ((KeyValuePair <long, string>) this.Vendor.SelectedItem).Key,
                VendorName   = ((KeyValuePair <long, string>) this.Vendor.SelectedItem).Value,
                Receiver     = ((KeyValuePair <long, string>) this.Receiver.SelectedItem).Value,
                ReceiverId   = ((KeyValuePair <long, string>) this.Receiver.SelectedItem).Key,
                ShipmentDate = DateTime.Now,
                //Comments = this.Comments.Text
            };

            List <ShipmentInventoryMapDTO> shipmentInventoryMap = new List <ShipmentInventoryMapDTO>();

            foreach (ShipmentInventoryItemDTO woii in shipmentInventoryList)
            {
                ShipmentInventoryMapDTO sim = new ShipmentInventoryMapDTO()
                {
                    InventoryId   = woii.InventoryId,
                    InventoryName = woii.InventoryName,
                    Quantity      = woii.Quantity
                };

                sim.ShipmentInventoryImageMap = woii.imageMap;

                shipmentInventoryMap.Add(sim);
            }

            addShipmentRequest.ShipmentDTO          = dto;
            addShipmentRequest.ShipmentInventoryMap = shipmentInventoryMap;

            ((App)App.Current).AddShipment(addShipmentRequest);

            this.Vendor.SelectedIndex   = -1;
            this.Receiver.SelectedIndex = -1;
            this.shipmentInventoryList.Clear();
            this.ShipmentItemsListView.ItemsSource = null;
            ((App)App.Current).ClearImageData();
        }
Exemplo n.º 17
0
        public ShipmentDTO Validate(string inputString)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(inputString))
                {
                    return(null);
                }

                // TODO: if input string is valid json string => then we need to deserialize that json string

                // this will deserialize the invalid string format (not json) shown as in example
                var arrStrShippment = inputString.Split(':');
                var arrStrPackages  = arrStrShippment[1].Split(' ');

                // Deserialize the input string to valid object
                ShipmentDTO oneShipment = new ShipmentDTO();
                oneShipment.MaxWeightAllowed = Int32.Parse(arrStrShippment[0]);

                foreach (var package in arrStrPackages)
                {
                    var arrPackage = package.Split(',');

                    PackageDTO onePackage = new PackageDTO();
                    onePackage.Index  = Int32.Parse(arrPackage[0].Replace("(", ""));
                    onePackage.Weight = Decimal.Parse(arrPackage[1]);
                    onePackage.Price  = arrPackage[2].Replace(")", "").Replace("€", ""); // "e.g. €45"

                    oneShipment.Packages.Add(onePackage);
                }

                return(oneShipment);
            }
            catch (Exception)
            {
                //TODO: Log exception

                return(null);
            }
        }
Exemplo n.º 18
0
        private void ShipmentReportListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //they've slected an individual shipment - fill the details list view
            try
            {
                ShipmentDTO item = (sender as ListView).SelectedValue as ShipmentDTO;

                ShipmentInventoryDTO s = shipments.ShipmentList.Where(a => a.Shipment.ShipmentId == item.ShipmentId).FirstOrDefault();

                list2.Clear();

                foreach (ShipmentInventoryMapDTO m in s.ShipmentInventoryMap)
                {
                    list2.Add(m);
                }

                ShipmentDetailListView.ItemsSource = list2;
            }
            catch (Exception ex)
            {
            }
        }
 public AddShipmentViewModel(ShipmentDTO shipment)
 {
     IsEdit           = true;
     ButtonLabel      = "Edit";
     this.toEdit      = shipment;
     ShippedItem      = shipment.ShippedItem;
     ItemQuantity     = shipment.ItemQuantity;
     RecipientCompany = shipment.RecipientCompany;
     CityTown         = shipment.CityTown;
     PostalCode1      = shipment.PostalCode.Substring(0, 2);
     PostalCode2      = shipment.PostalCode.Substring(3, 3);
     StreetAddress    = shipment.StreetAddress;
     Weight           = shipment.Weight;
     Description      = shipment.Description;
     NotifyOfPropertyChange(() => ShippedItem);
     NotifyOfPropertyChange(() => ItemQuantity);
     NotifyOfPropertyChange(() => RecipientCompany);
     NotifyOfPropertyChange(() => CityTown);
     NotifyOfPropertyChange(() => PostalCode1);
     NotifyOfPropertyChange(() => PostalCode2);
     NotifyOfPropertyChange(() => StreetAddress);
     NotifyOfPropertyChange(() => Weight);
     NotifyOfPropertyChange(() => Description);
 }
Exemplo n.º 20
0
        public MemoryStream CreateWordInvoice(ShipmentDTO shipment)
        {
            var    body     = new Body();
            var    document = new Document(body);
            string fontName = "Times New Roman";

            var table   = CreateTable();
            var headRow = new TableRow();

            table.Append(headRow);
            headRow.Append(new TableCell(CreateParagraph("№", fontName, 12, JustificationValues.Center)));
            headRow.Append(new TableCell(CreateParagraph("Код", fontName, 12, JustificationValues.Center)));
            headRow.Append(new TableCell(CreateParagraph("Товар", fontName, 12, JustificationValues.Center)));
            headRow.Append(new TableCell(CreateParagraph("Кол-во", fontName, 12, JustificationValues.Center)));
            headRow.Append(new TableCell(CreateParagraph("Ед.", fontName, 12, JustificationValues.Center)));
            headRow.Append(new TableCell(CreateParagraph("Цена", fontName, 12, JustificationValues.Center)));
            headRow.Append(new TableCell(CreateParagraph("Сумма", fontName, 12, JustificationValues.Center)));

            int i = 1;

            foreach (var orderItem in shipment.Order.Items)
            {
                var row = new TableRow();
                table.Append(row);
                row.Append(new TableCell(CreateParagraph(i.ToString(), fontName, 12, JustificationValues.Center)));
                row.Append(new TableCell(CreateParagraph(orderItem.ProductId.ToString(), fontName, 12, JustificationValues.Center)));
                row.Append(new TableCell(CreateParagraph(orderItem.Product.Name, fontName, 12, JustificationValues.Center)));
                row.Append(new TableCell(CreateParagraph("1", fontName, 12, JustificationValues.Center)));
                row.Append(new TableCell(CreateParagraph(orderItem.Product.Unit.ToString(), fontName, 12, JustificationValues.Center)));
                row.Append(new TableCell(CreateParagraph(orderItem.Price.ToString(), fontName, 12, JustificationValues.Center)));
                row.Append(new TableCell(CreateParagraph((new Price(orderItem.Price.Penny * 1)).ToString(), fontName, 12, JustificationValues.Center)));
                ++i;
            }

            var table2 = CreateTable(BorderValues.None);
            var row2   = new TableRow();

            row2.Append(new TableCell(CreateParagraph("Сдал:")));
            row2.Append(new TableCell(CreateParagraph(shipment.Conveyed.UserName ?? shipment.ConveyedName)));
            row2.Append(new TableCell(CreateParagraph("____________")));
            row2.Append(new TableCell(CreateParagraph("подпись")));
            table2.Append(row2);

            row2 = new TableRow();
            row2.Append(new TableCell(CreateParagraph("Получил:")));
            row2.Append(new TableCell(CreateParagraph(shipment.Repicient.UserName ?? shipment.RepicientName)));
            row2.Append(new TableCell(CreateParagraph("____________")));
            row2.Append(new TableCell(CreateParagraph("подпись")));
            table2.Append(row2);

            document.Append(CreateParagraph($"Накладная №{shipment.Id} от {shipment.DateTime.ToString("dd MMMM yyyy")}", fontName, 16, JustificationValues.Center));
            document.Append(table);
            document.Append(CreateParagraph($"Итого {shipment.Order.TotalPrice}"));
            document.Append(table2);

            MemoryStream resultStream = new MemoryStream();

            using (var doc = WordprocessingDocument.Create(
                       resultStream, WordprocessingDocumentType.Document))
            {
                doc.AddMainDocumentPart();
                doc.MainDocumentPart.Document = document;
                doc.MainDocumentPart.Document.Save();
            }
            resultStream.Flush();
            resultStream.Position = 0;
            return(resultStream);
        }
Exemplo n.º 21
0
 public async Task UpdateAsync(ShipmentDTO item)
 {
     var mappedItem = _mapper.Map <Shipment>(item);
     await _repo.UpdateAsync(mappedItem);
 }
Exemplo n.º 22
0
 public async Task DeleteAsync(ShipmentDTO item)
 {
     await _repo.DeleteAsync(_mapper.Map <Shipment>(item));
 }
Exemplo n.º 23
0
        public List <int> CalculatePackage(ShipmentDTO shippment)
        {
            try
            {
                //TODO: AutoMapper from DTO to entites

                // validate packages base on creteria required
                List <PackageDTO> validPackages = _validatePackage.Validate(shippment.Packages, shippment.MaxWeightAllowed);
                if (!validPackages.Any())
                {
                    return(null);
                }

                List <PackageDTO> validPackagesOrdered = validPackages
                                                         .OrderByDescending(x => x.Price)
                                                         .ThenByDescending(z => z.Weight).ToList();

                List <PackValue> packVal = new List <PackValue>(); // will hold final list of all packages combinations that are fulfill the criteria
                if (validPackagesOrdered.Count > 1)                // if there are more then one packages select them
                {
                    for (int i = 0; i < validPackagesOrdered.Count; i++)
                    {
                        var currentPack = validPackagesOrdered[i];

                        // add this package to the list as single first
                        packVal.Add(new PackValue()
                        {
                            Price   = decimal.Parse(currentPack.Price),
                            Indexes = new List <int>()
                            {
                                currentPack.Index
                            }
                        });

                        // foreach valid packages find other packages to match and increase the value but not more then max weight value
                        var stackPack = new Stack <PackageDTO>(validPackagesOrdered);
                        while (stackPack.Count > 0)
                        {
                            PackageDTO packFromStack = stackPack.Pop();

                            if (currentPack.Index != packFromStack.Index)
                            {
                                if ((currentPack.Weight + packFromStack.Weight) <= shippment.MaxWeightAllowed)
                                {
                                    List <int> newIndexList = new List <int>();
                                    newIndexList.Add(currentPack.Index);
                                    newIndexList.Add(packFromStack.Index);

                                    decimal currentMaxPrice = (decimal.Parse(currentPack.Price) + decimal.Parse(packFromStack.Price));

                                    // if there is unused weight then search packages with weight less then unused and add them to the list (to increase the value)
                                    var unusedWeight = shippment.MaxWeightAllowed - (currentPack.Weight + packFromStack.Weight);
                                    var packagesList = validPackagesOrdered.Where(
                                        x => x.Weight <= unusedWeight &&
                                        x.Index != currentPack.Index &&
                                        x.Index != packFromStack.Index)
                                                       .OrderByDescending(y => y.Price)
                                                       .ThenByDescending(z => z.Weight).ToList();

                                    if (packagesList.Any())
                                    {
                                        newIndexList.Add(packagesList.First().Index);
                                        currentMaxPrice = currentMaxPrice + decimal.Parse(packagesList.First().Price);
                                    }

                                    // add the pack
                                    packVal.Add(new PackValue()
                                    {
                                        Price   = currentMaxPrice,
                                        Indexes = newIndexList
                                    });;
                                }
                            }
                        }
                    }
                }
                else
                {
                    // add the pack
                    packVal.Add(new PackValue()
                    {
                        Price   = decimal.Parse(validPackagesOrdered.First().Price),
                        Indexes = new List <int>()
                        {
                            validPackagesOrdered.First().Index
                        }
                    });;
                }

                // order valid packages by value(price)
                var maxValuePack = packVal.OrderByDescending(x => x.Price);

                // return packages with most combine price
                return(maxValuePack.First().Indexes);
            }
            catch (Exception)
            {
                // TODO: Log error

                return(null);
            }
        }
Exemplo n.º 24
0
        public void AddShipment()
        {
            try
            {
                AddShipmentRequest addShipmentRequest = new AddShipmentRequest();

                ShipmentDTO dto = new ShipmentDTO()
                {
                    VendorId     = ((KeyValuePair <long, string>) this.VendorComboBox.SelectedValue).Key,
                    ShipmentDate = this.ShipmentDate.SelectedDate.HasValue ? this.ShipmentDate.SelectedDate.Value : DateTime.Now
                };


                foreach (ShipmentInventoryItemDTO itemDTO in shipmentInventoryList)
                {
                    shipmentInventoryMap.Add(new ShipmentInventoryMapDTO()
                    {
                        InventoryId   = itemDTO.InventoryId,
                        InventoryName = itemDTO.InventoryName,
                        Quantity      = itemDTO.Quantity
                    });
                }

                addShipmentRequest.ShipmentDTO          = dto;
                addShipmentRequest.ShipmentInventoryMap = shipmentInventoryMap;

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:9000/");
                //client.DefaultRequestHeaders.Add("appkey", "myapp_key");
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("EO-Header", wnd.User + " : " + wnd.Pwd);

                string jsonData = JsonConvert.SerializeObject(addShipmentRequest);
                var    content  = new StringContent(jsonData, Encoding.UTF8, "application/json");
                HttpResponseMessage httpResponse = client.PostAsync("api/Login/AddShipment", content).Result;
                if (httpResponse.IsSuccessStatusCode)
                {
                    Stream       streamData = httpResponse.Content.ReadAsStreamAsync().Result;
                    StreamReader strReader  = new StreamReader(streamData);
                    string       strData    = strReader.ReadToEnd();
                    strReader.Close();
                    ApiResponse apiResponse = JsonConvert.DeserializeObject <ApiResponse>(strData);

                    if (apiResponse.Messages.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (KeyValuePair <string, List <string> > messages in apiResponse.Messages)
                        {
                            foreach (string msg in messages.Value)
                            {
                                sb.AppendLine(msg);
                            }
                        }

                        MessageBox.Show(sb.ToString());
                    }
                    else
                    {
                        this.ShipmentListView.ItemsSource = null;
                    }
                }
                else
                {
                    MessageBox.Show("Error adding Shipment");
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 25
0
 public AddShipmentRequest(ShipmentDTO dto, List <ShipmentInventoryMapDTO> mapDTO, List <ShipmentInventoryImageMapDTO> imageMapDTO)
 {
     ShipmentDTO               = dto;
     ShipmentInventoryMap      = mapDTO;
     ShipmentInventoryImageMap = imageMapDTO;
 }