Пример #1
0
        public bool RegisterDelivery(AddDeliveryViewModel deliveryVM)
        {
            var delivery = new Delivery()
            {
                //TODO need to use automapper here for sure
                SenderId = CurrentUser.Id,
                Number = Guid.NewGuid().ToString(),
                DestinationAddress = deliveryVM.DestinationAddress,
                PickupAddress = deliveryVM.PickupAddress,
                AdditionalInfo = deliveryVM.AdditionalInfo,
                Content = deliveryVM.Content,
                DeliveryDate = deliveryVM.DeliveryDate,
                ReceiptDate = deliveryVM.ReceiptDate,
                Height = deliveryVM.Height,
                Width = deliveryVM.Width,
                Weight = deliveryVM.Weight,
                Length = deliveryVM.Length
            };

            delivery.AddTrackingHistoryPoint(GenerateTrackingPoint(TrackingStatus.RegistredInSystem, delivery.PickupAddress.City));

            using (var db = DataFactory.GetDataContext())
            {
                db.Deliveries.Add(delivery);
                db.SaveChanges();
            }

            return true;
        }
Пример #2
0
        public ActionResult AddDelivery(AddDeliveryViewModel delivery)
        {
            if (ModelState.IsValid)
            {
                var result = _deliveryService.RegisterDelivery(delivery)
                    ? string.Format("Przesyłka zostanie odebrana z {0} oraz wysłana do {1}", delivery.PickupAddress.City,
                        delivery.DestinationAddress.City)
                    : "Błąd";

                return Content(result);
            }

            return View(delivery);
        }