public void AddCurrentRoute_CorrectData_RouteCreated()
        {
            CourierDto courier = new CourierDto()
            {
                FirstName   = "Courier",
                LastName    = "With route",
                PhoneNumber = "test"
            };

            Guid id = courierService.AddCourierAsync(courier).Result;

            RouteDto route = new RouteDto()
            {
                Created = DateTime.Now,
                Points  = new List <PointDto>
                {
                    new PointDto {
                        Latitude = 49.8333981, Longitude = 24.0125249
                    },
                    new PointDto {
                        Latitude = 49.8306805, Longitude = 24.034673
                    },
                    new PointDto {
                        Latitude = 49.8388715, Longitude = 24.0311097
                    }
                }
            };

            Guid routeId = routeService.AddRouteAsync(id, route).Result;

            Assert.IsTrue(routeId != Guid.Empty);
        }
Example #2
0
        private async void button2_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (this.dataGridView1.CurrentRow == null)
                {
                    throw new Exception("Выберите курьера для удаления.");
                }

                var lastName   = this.textBox1.Text;
                var name       = this.textBox2.Text;
                var patronimyc = this.textBox3.Text;
                var passport   = this.textBox7.Text;
                var address    = this.textBox4.Text;
                var phone1     = this.textBox5.Text;
                var phone2     = this.textBox6.Text;
                var date       = this.dateTimePicker1.Value;

                var courierId = long.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString());
                var courier   = new CourierDto(lastName, name, patronimyc, passport, address, phone1, phone2, date)
                {
                    CourierId = courierId
                };

                await this.courierManager.DeleteCourierAsync(courier);

                this.FillCourierTable();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void ChangeCourierLocation_CorrectData()
        {
            CourierDto courier = new CourierDto()
            {
                FirstName   = "Courier",
                LastName    = "change location",
                PhoneNumber = "testphone",
                Location    = new PointDto()
                {
                    Latitude = 23.02, Longitude = 54.03
                }
            };

            Guid id = courierService.AddCourierAsync(courier).Result;

            PointDto newLocation = new PointDto()
            {
                Latitude = 27.34, Longitude = 43.15
            };

            courierService.ChangeCourierLocationAsync(courier.Id, newLocation).Wait();

            CourierDto courierWithNewLocation = courierService.GetCourierById(courier.Id);

            Assert.IsTrue(courier.Location.Latitude != courierWithNewLocation.Location.Latitude &&
                          courier.Location.Longitude != courierWithNewLocation.Location.Longitude);
        }
        private long PrepareData()
        {
            CourierDto[] couriers = new CourierDto[]
            {
                CourierFactory(new PointDto(49.83498756, 24.03488874)),
                CourierFactory(new PointDto(49.83609475, 24.02265787)),
                CourierFactory(new PointDto(49.84495134, 24.03587579)),
                CourierFactory(new PointDto(49.84401041, 23.98257493)),
                CourierFactory(new PointDto(49.82712580, 23.98296117)),
                CourierFactory(new PointDto(49.82014880, 23.98823976)),
                CourierFactory(new PointDto(49.82390000, 24.02079100)),
                CourierFactory(new PointDto(49.83226000, 24.01255100))
            };

            foreach (var courier in couriers)
            {
                courierService.AddCourierAsync(courier).Wait();
            }

            var warehouseId = warehouseService.AddWarehouseAsync(new WarehouseDto()
            {
                Location = new PointDto(49.83425819, 24.01567876), Name = "Warehouse for order"
            }).Result;

            var order = OrderFactory(new PointDto(49.830213, 24.030651), warehouseId);

            long orderId = orderService.AddOrderAsync(order).Result;

            return(orderId);
        }
Example #5
0
        public async Task DeleteCourierAsync(CourierDto courierDto)
        {
            var courier =
                await this.courierRepository.Entity.FirstOrDefaultAsync(x => x.CourierId == courierDto.CourierId);

            this.courierRepository.Entity.Remove(courier ?? throw new ArgumentException("Не найден курьер для удаления."));
            await this.courierRepository.SaveChangesAsync();
        }
Example #6
0
        private void Validate(CourierDto courier)
        {
            var validate = DataAnnotationsValidator.Validate(courier);

            if (!validate.Success)
            {
                throw new ArgumentException(validate.ErrorMessage);
            }
        }
        public CourierDto GetCourierById(Guid courierId)
        {
            using (var db = new CourierHelperDb(_connectionString))
            {
                Courier courier = db.CouriersRepo.Get(courierId);

                CourierDto courierDto = Mapper.Map <CourierDto>(courier);

                return(courierDto);
            }
        }
        public void AddCourierWithoutLocation_CorrectData_NewCourierIdIsExists()
        {
            CourierDto courier = new CourierDto()
            {
                FirstName   = "Courier",
                LastName    = "Two",
                PhoneNumber = "testphone"
            };

            Guid id = courierService.AddCourierAsync(courier).Result;

            courier = courierService.GetCourierById(id);

            Assert.IsNotNull(courier);
        }
Example #9
0
        public IHttpActionResult UpdateProfileInfo(CourierDto userData)
        {
            var courier = _courierService.GetById(userData.Id);

            //courier = userData.MapPropertiesToInstance(courier);
            courier.CarNo            = userData.CarNo;
            courier.User.Email       = userData.User.Email;
            courier.User.MobilePhone = userData.User.MobilePhone.RemoveFormatPhone();
            var newPassword = PasswordHelper.HashString(userData.User.Password, courier.User.UserName);

            courier.User.Password = newPassword;
            var result     = _courierService.Update(courier);
            var courierDto = result.MapTo <CourierDto>();

            courierDto.User.Password = userData.User.Password;
            return(Ok(courierDto));
        }
Example #10
0
        public async Task AddCourierAsync(CourierDto courierDto)
        {
            var courier = SimpleAutoMapperTransformer.Transform <CourierDto, Courier>(courierDto);

            this.Validate(courierDto);

            if (await this.courierRepository.Entity.AnyAsync(
                    x => x.LastName == courier.LastName && x.Name == courier.Name &&
                    x.Patronymic == courier.Patronymic &&
                    x.Address == courier.Address &&
                    x.HireDate == courier.HireDate))
            {
                throw new ArgumentException("Такой курьер уже существует.");
            }

            this.courierRepository.Entity.Add(courier);
            await this.courierRepository.SaveChangesAsync();
        }
        public void AddCourierWithLocation_CorrectData_NewCourierIdIsExists()
        {
            CourierDto courier = new CourierDto()
            {
                FirstName   = "Courier",
                LastName    = "One",
                PhoneNumber = "testphone",
                Location    = new PointDto()
                {
                    Latitude = 23.02, Longitude = 54.03
                }
            };

            Guid id = courierService.AddCourierAsync(courier).Result;

            courier = courierService.GetCourierById(id);

            Assert.IsNotNull(courier);
        }
        public void GetDisabledCourier_CorrectData_ReturnsNull()
        {
            CourierDto courier = new CourierDto()
            {
                FirstName   = "Courier",
                LastName    = "Disabled",
                PhoneNumber = "testphone",
                Location    = new PointDto()
                {
                    Latitude = 23.02, Longitude = 54.03
                }
            };

            Guid id = courierService.AddCourierAsync(courier).Result;

            courierService.DisableCourierAsync(id).Wait();

            courier = courierService.GetCourierById(id);

            Assert.IsNull(courier);
        }
        public void ChangeCourierState_CorrectData()
        {
            CourierDto courier = new CourierDto()
            {
                FirstName   = "Courier",
                LastName    = "change location",
                PhoneNumber = "testphone",
                Location    = new PointDto()
                {
                    Latitude = 23.02, Longitude = 54.03
                }
            };

            Guid id = courierService.AddCourierAsync(courier).Result;

            courierService.ChangeCourierStateAsync(id, CourierStateDto.Idle).Wait();

            courier = courierService.GetCourierById(id);

            Assert.IsTrue(courier.State == CourierStateDto.Idle);
        }
Example #14
0
        public void ChangeCurrentRoute_CorrectData_CurrentRouteChanged()
        {
            CourierDto courier = new CourierDto()
            {
                FirstName   = "Courier",
                LastName    = "With route 2",
                PhoneNumber = "test"
            };

            Guid id = courierService.AddCourierAsync(courier).Result;

            RouteDto route = new RouteDto()
            {
                Created = DateTime.Now,
                Points  = new List <PointDto>
                {
                    new PointDto {
                        Latitude = 49.8333981, Longitude = 24.0125249
                    },
                    new PointDto {
                        Latitude = 49.8306805, Longitude = 24.034673
                    },
                    new PointDto {
                        Latitude = 49.8388715, Longitude = 24.0311097
                    }
                }
            };

            Guid routeId = routeService.AddRouteAsync(id, route).Result;

            route.Points.Add(new PointDto {
                Latitude = 49.846458, Longitude = 24.0257161
            });
            routeService.ChangeCourierCurrentRouteAsync(id, route).Wait();

            route = routeService.GetCourierCurrentRoute(id);

            Assert.IsTrue(route.Points.Count == 4 && route.Points.Last().Latitude == 49.846458);
        }
        public void GetNearestCouriers_CorrectData_ListOfCouriersIsNotEmpty()
        {
            CourierDto[] couriers = new CourierDto[]
            {
                CourierFactory(new PointDto(49.83498756, 24.03488874)),
                CourierFactory(new PointDto(49.83609475, 24.02265787)),
                CourierFactory(new PointDto(49.84495134, 24.03587579)),
                CourierFactory(new PointDto(49.84401041, 23.98257493)),
                CourierFactory(new PointDto(49.82712580, 23.98296117)),
                CourierFactory(new PointDto(49.82014880, 23.98823976)),
                CourierFactory(new PointDto(49.82390000, 24.02079100)),
                CourierFactory(new PointDto(49.83226000, 24.01255100))
            };

            foreach (var courier in couriers)
            {
                courierService.AddCourierAsync(courier).Wait();
            }

            var result = courierService.GetNearestCouriers(new PointDto(49.830213, 24.030651), 3);

            Assert.IsTrue(result.Count == 3 && result.First().Location.Latitude == 49.83498756);
        }
Example #16
0
        private async void button3_Click(object sender, System.EventArgs e)
        {
            try
            {
                var lastName   = this.textBox1.Text;
                var name       = this.textBox2.Text;
                var patronimyc = this.textBox3.Text;
                var passport   = this.textBox7.Text;
                var address    = this.textBox4.Text;
                var phone1     = this.textBox5.Text;
                var phone2     = this.textBox6.Text;
                var date       = this.dateTimePicker1.Value;

                var courier = new CourierDto(lastName, name, patronimyc, passport, address, phone1, phone2, date);

                await this.courierManager.AddCourierAsync(courier);

                this.FillCourierTable();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public async Task <Guid> AddCourierAsync(CourierDto courierDto)
        {
            if (string.IsNullOrWhiteSpace(courierDto.PhoneNumber))
            {
                throw new ArgumentException("Phone number is required");                 //todo: better exception
            }

            using (var db = new CourierHelperDb(_connectionString))
            {
                Courier courier = new Courier
                {
                    FirstName   = courierDto.FirstName,
                    LastName    = courierDto.LastName,
                    MiddleName  = courierDto.MiddleName,
                    Email       = courierDto.Email,
                    PhoneNumber = courierDto.PhoneNumber,
                    State       = (CourierState)courierDto.State
                };

                if (courierDto.Location != null)
                {
                    ActivePoint location = new ActivePoint
                    {
                        Coordinates = new Point(courierDto.Location.Longitude, courierDto.Location.Latitude)
                    };

                    courier.Location = location;
                }

                db.CouriersRepo.Create(courier);
                await db.SaveAsync();

                courierDto.Id = courier.Id;
                return(courier.Id);
            }
        }
        public IHttpActionResult GetById(Guid courierId)
        {
            CourierDto courier = CourierService.GetCourierById(courierId);

            return(Ok(courier));
        }
Example #19
0
 public Task UpdateCourierAsync(CourierDto courierDto)
 {
     this.Validate(courierDto);
     this.courierRepository.Entity.AddOrUpdate(SimpleAutoMapperTransformer.Transform <CourierDto, Courier>(courierDto));
     return(this.courierRepository.SaveChangesAsync());
 }