Exemple #1
0
 public IActionResult Delete(int id)
 {
     try
     {
         CourierLocation db_courier = _courierContext.GetWithId(id);
         if (db_courier == null)
         {
             return(StatusCode(StatusCodes.Status500InternalServerError, new Response
             {
                 Status = "Error",
                 Messages = new Message[] {
                     new Message {
                         Lang_id = 1,
                         MessageLang = "Model state isn't valid!"
                     },
                     new Message {
                         Lang_id = 2,
                         MessageLang = "Состояние модели недействительно!"
                     },
                     new Message {
                         Lang_id = 3,
                         MessageLang = "Model vəziyyəti etibarsızdır!"
                     }
                 }
             }));
         }
         db_courier.IsDeleted = true;
         _courierContext.Update(db_courier);
         return(Ok());
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }
Exemple #2
0
        public static async Task SeedAsync(IApplicationBuilder applicationBuilder, ILoggerFactory loggerFactory)
        {
            var config  = applicationBuilder.ApplicationServices.GetRequiredService <IOptions <CourierSettings> >();
            var context = new CourierContext(config);

            if (!context.Couriers.Database.GetCollection <Model.Courier>("Couriers").AsQueryable().Any())
            {
                var courier = new Model.Courier
                {
                    FirstName = "John",
                    LastName  = "Doe",
                    Phone     = "+112233445566"
                };
                await context.Couriers.InsertOneAsync(courier);

                var courierLocation = new CourierLocation
                {
                    CourierId = courier.Id,
                    DateTime  = DateTime.UtcNow,
                    Latitude  = 0.1223,
                    Longitude = 1.2111
                };
                await context.CourierLocations.InsertOneAsync(courierLocation);
            }
        }
Exemple #3
0
        public IActionResult SaveLocationToDatabase([FromBody] CourierLocation location)
        {
            //location.LocationTime = DateTime.Now;

            try{
                _context.CourierLocation.Add(location);
                _context.SaveChanges();
            }
            catch (Exception ex) { }

            return(Ok(location));
        }
Exemple #4
0
        public CourierLocation GetCourierLocationById(int id)
        {
            CourierLocation courierLocation = _context.CourierLocation.Where(x => x.CourierId == id).LastOrDefault();

            if (courierLocation != null)
            {
                return(courierLocation);
            }
            else
            {
                return(new CourierLocation());
            }
        }
Exemple #5
0
 public IActionResult Create([FromForm] CourierLocation courier)
 {
     try
     {
         courier.CourierTranslates = JsonSerializer.Deserialize <ICollection <CourierTranslate> >(courier.Translates);
         if (!ModelState.IsValid)
         {
             return(StatusCode(StatusCodes.Status500InternalServerError, new Response
             {
                 Status = "Error",
                 Messages = new Message[] {
                     new Message {
                         Lang_id = 1,
                         MessageLang = "Model state isn't valid!"
                     },
                     new Message {
                         Lang_id = 2,
                         MessageLang = "Состояние модели недействительно!"
                     },
                     new Message {
                         Lang_id = 3,
                         MessageLang = "Model vəziyyəti etibarsızdır!"
                     }
                 }
             }));
         }
         _courierContext.Add(courier);
         foreach (CourierTranslate item in courier.CourierTranslates)
         {
             item.CourierLocationId = courier.Id;
             _courierTranslateContext.Add(item);
         }
         return(Ok());
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }
 public Task InsertCourierLocationAsync(CourierLocation courierLocation)
 {
     return(_courierContext.CourierLocations.InsertOneAsync(courierLocation));
 }
        public ActionResult CheckStats(int id)
        {
            List <CourierLocation> courierLocation = new List <CourierLocation>();
            StatsModel             statModel       = new StatsModel();
            var measuresDate = DateTime.Now;

            using (MyDBContext dbc = new MyDBContext())
            {
                var myLocationList = dbc.CourierLocation.Where(x => x.CourierId == id && x.LocationTime.Year == measuresDate.Year && x.LocationTime.Month == measuresDate.Month && x.LocationTime.Day == measuresDate.Day).Include(x => x.Courier).ToList();

                foreach (var user in myLocationList)
                {
                    user.Courier.UserDetails.User = null;
                }

                courierLocation = myLocationList;


                if (courierLocation.Count == 0)
                {
                    CourierLocation firstLoc = new CourierLocation()
                    {
                        CourierId = id
                    };
                    courierLocation.Add(firstLoc);
                }

                foreach (var val in courierLocation)
                {
                    val.StringLocationTime = val.LocationTime.ToString("hh:mm");
                }

                statModel.CourierLocations = courierLocation;
                statModel.CourierId        = id;
                statModel.ChosenDate       = DateTime.Now;


                statModel.NrOfDeliveredPackages = dbc.DeliveredPackages.Where(x => x.CourierId == id && x.SubmitTime.Year == measuresDate.Year && x.SubmitTime.Month == measuresDate.Month && x.SubmitTime.Day == measuresDate.Day).Count();;


                List <String> myObsList = dbc.DeliveredPackages.Where(x => x.CourierId == id && x.SubmitTime.Year == measuresDate.Year && x.SubmitTime.Month == measuresDate.Month && x.SubmitTime.Day == measuresDate.Day).Select(z => z.Observations).ToList();
                statModel.Observations = "";
                if (myObsList.Count > 0)
                {
                    foreach (var obs in myObsList)
                    {
                        statModel.Observations += obs.ToString() + ", ";
                    }
                }

                double totalDistance = 0;
                for (var i = 0; i < statModel.CourierLocations.Count - 1; i++)
                {
                    var sCoord = new GeoCoordinate(statModel.CourierLocations[i].Latitude, statModel.CourierLocations[i].Longitude);
                    var eCoord = new GeoCoordinate(statModel.CourierLocations[i + 1].Latitude, statModel.CourierLocations[i + 1].Longitude);

                    var distanceAB = sCoord.GetDistanceTo(eCoord); //in m
                    totalDistance += distanceAB;
                }

                //transform from m to km
                statModel.Mileage = totalDistance / 1000;
                statModel.Mileage = Math.Round(statModel.Mileage, 2);

                var CarFuelConsumption = dbc.User.Where(x => x.Id == id).Include(z => z.Car).Select(y => y.Car.LPerHundredKm).FirstOrDefault();
                statModel.AproxSpentFuel = (Convert.ToDouble(CarFuelConsumption) * statModel.Mileage) / 100;
                statModel.AproxSpentFuel = Math.Round(statModel.AproxSpentFuel, 2);
            }
            return(View(statModel));
        }
Exemple #8
0
        public IActionResult PutAsync(int id, [FromForm] CourierLocation courier)
        {
            try
            {
                courier.CourierTranslates = JsonSerializer.Deserialize <ICollection <CourierTranslate> >(courier.Translates);
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                CourierLocation db_courier = _courierContext.GetWithId(id);
                if (db_courier == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }

                db_courier.IsActived = courier.IsActived;
                db_courier.Price     = courier.Price;
                _courierContext.Update(db_courier);
                foreach (CourierTranslate item in courier.CourierTranslates)
                {
                    CourierTranslate db_Translate = _courierTranslateContext.GetWithId(item.Id);
                    db_Translate.Name = item.Name;
                    _courierTranslateContext.Update(db_Translate);
                }

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
Exemple #9
0
 public void Update(CourierLocation data)
 {
     _context.Update(data);
 }
Exemple #10
0
 public void Add(CourierLocation data)
 {
     _context.Add(data);
 }