Ejemplo n.º 1
0
        public string InsertOrUpdateDeliveryRouteChild(DeliveryRouteDTO deliveryRoute)
        {
            string stat;

            try
            {
                //var validate = ValidateChild(deliveryLine);
                if (deliveryRoute == null)
                {
                    return("DeliveryRoute is Null");
                }

                //if (ObjectExistsChild(deliveryLine))
                //    return GenericDeliveryRoutes.DatabaseErrorRecordAlreadyExists;

                _deliveryLineDeliveryRouteRepository.InsertUpdate(deliveryRoute);
                _unitOfWork.Commit();
                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                Dispose(_disposeWhenDone);
            }
            return(stat);
        }
Ejemplo n.º 2
0
        public string InsertOrUpdateChild(DeliveryLineDTO deliveryLine)
        {
            try
            {
                var validate = ValidateChild(deliveryLine);
                if (!string.IsNullOrEmpty(validate))
                {
                    return(validate);
                }

                if (ObjectExistsChild(deliveryLine))
                {
                    return(GenericMessages.DatabaseErrorRecordAlreadyExists);
                }

                //insert delivery route for each delivery line
                var deliveryRoute = GetDeliveryRouteChilds(deliveryLine.Id, false).FirstOrDefault();
                if (deliveryRoute == null)
                {
                    deliveryRoute = new DeliveryRouteDTO();
                    if (deliveryLine.Id != 0)
                    {
                        deliveryRoute.DeliveryLineId = deliveryLine.Id;
                    }
                    else
                    {
                        deliveryRoute.DeliveryLine = deliveryLine;
                    }

                    deliveryRoute.DeliveryType  = deliveryLine.DeliveryType;
                    deliveryRoute.FromAddressId = null;
                    deliveryRoute.ToAddressId   = null;
                    deliveryRoute.StartedTime   = null;
                    deliveryRoute.EndedTime     = null;
                    deliveryRoute.Id            = 0;

                    _deliveryLineDeliveryRouteRepository.InsertUpdate(deliveryRoute);
                }

                _deliveryLineRepository.InsertUpdate(deliveryLine);

                _unitOfWork.Commit();
                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
        public async Task <DeliveryRouteDTO> GetDeliveryRoute(long deliveryID)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(API.url + "delivery-routes/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            DeliveryRouteDTO    deliveryRoute = null;
            HttpResponseMessage response      = await client.GetAsync(deliveryID.ToString()).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                deliveryRoute = JsonConvert.DeserializeObject <DeliveryRouteDTO>(responseString);
                return(deliveryRoute);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public string DisableDeliveryRouteChild(DeliveryRouteDTO deliveryRoute)
        {
            string stat;

            try
            {
                var msg = FindDeliveryRouteChild(deliveryRoute.Id.ToString(CultureInfo.InvariantCulture));
                msg.Enabled = false;
                _deliveryLineDeliveryRouteRepository.Update(msg);
                _unitOfWork.Commit();
                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                Dispose(_disposeWhenDone);
            }
            return(stat);
        }
Ejemplo n.º 5
0
 private void ResetDeliveryLine()
 {
     SelectedDeliveryRoute = new DeliveryRouteDTO
     {
     };
 }
Ejemplo n.º 6
0
        private void SaveDeliveryLine(object obj)
        {
            try
            {
                SelectedDeliveryRoute.AssignedToStaffId = SelectedStaff.Id;
                if (SelectedVehicle != null)
                {
                    SelectedDeliveryRoute.VehicleId = SelectedVehicle.Id;
                }

                SelectedDeliveryRoute.FromAddressId = SelectedCompany.AddressId;
                SelectedDeliveryRoute.ToAddressId   = SelectedDelivery.OrderByClient.AddressId;
                _deliveryService.InsertOrUpdateDeliveryRouteChild(SelectedDeliveryRoute);

                var delivery = _deliveryService.Find(SelectedDelivery.Id.ToString());

                delivery.DeliverDirectly = DeliverDirectly;

                delivery.Status = DeliveryStatusTypes.AcceptanceScheduled;
                if (SelectedDeliveryRoute.StartedTime != null)
                {
                    delivery.Status = DeliveryStatusTypes.OnAcceptance;
                }
                if (SelectedDeliveryRoute.StartedTime != null && SelectedDeliveryRoute.EndedTime != null)
                {
                    delivery.Status = DeliveryStatusTypes.Accepted;
                }
                _deliveryService.InsertOrUpdate(delivery);

                //Create Delivery Route for each Line
                var delLines = SelectedDelivery.DeliveryLines.Where(
                    d => d.DeliveryType == DeliveryLineRouteTypes.Delivering).ToList();
                foreach (var deliveryLineDTO in delLines)
                {
                    var delRoute =
                        _deliveryService.GetDeliveryRouteChilds(deliveryLineDTO.Id, false).FirstOrDefault();

                    if (DeliverDirectly && delRoute == null)
                    {
                        delRoute = new DeliveryRouteDTO();
                        delRoute = (DeliveryRouteDTO)MapperUtility <DeliveryRouteDTO> .GetMap(SelectedDeliveryRoute, delRoute);

                        delRoute.DeliveryType   = DeliveryLineRouteTypes.Delivering;
                        delRoute.DeliveryLine   = null;
                        delRoute.DeliveryLineId = deliveryLineDTO.Id;
                        delRoute.FromAddressId  = SelectedDelivery.OrderByClient.AddressId;
                        delRoute.StartedTime    = null;
                        delRoute.EndedTime      = null;
                        delRoute.Id             = 0;

                        _deliveryService.InsertOrUpdateDeliveryRouteChild(delRoute);
                    }
                    if (delRoute != null && !DeliverDirectly)
                    {
                        delRoute.Enabled = false;
                        _deliveryService.InsertOrUpdateDeliveryRouteChild(delRoute);
                    }
                }

                CloseWindow(obj);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Can't save"
                                + Environment.NewLine + exception.Message, "Can't save", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }