예제 #1
0
        public ActionResult Print(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var dto = DeliverySerializer.LoadFromStream(file.InputStream);
                return(View(dto));
            }

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Print(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var dto = DeliverySerializer.LoadFromStream(file.InputStream);
                Dictionary <string, int> titleArray = new Dictionary <string, int>();
                using (var db = new ApplicationDbContext())
                {
                    var row = new DbDeliveryRquest
                    {
                        ClientAddress = dto.ClientAddress,
                        Filled        = dto.Filled,
                        TimeDeliver   = dto.TimeDeliver,
                        TotalCost     = dto.TotalCost,
                        FullName      = dto.FullName
                    };

                    row.WayPoints = new Collection <DbWayPoint>();
                    foreach (var wpDto in dto.WayPoints)
                    {
                        var wp = new DbWayPoint
                        {
                            Address    = wpDto.Address,
                            PlaceTitle = wpDto.PlaceTitle,
                            ShopType   = wpDto.ShopType,
                        };
                        row.WayPoints.Add(wp);
                        wp.ProductsList = new Collection <DbProduct>();
                        foreach (var product in wpDto.ProductsList)
                        {
                            var p = new DbProduct
                            {
                                Name      = product.Name,
                                Amount    = product.Amount,
                                Additions = product.Additions,
                                Cost      = product.Cost,
                            };
                            wp.ProductsList.Add(p);
                        }
                        db.productList.AddRange(wp.ProductsList);
                    }
                    db.DeliveryRequest.Add(row);
                    db.SaveChanges();
                    return(View(dto));
                }
            }
            return(RedirectToAction("Index"));
        }