コード例 #1
0
 /// <summary>
 /// Create payment.
 /// </summary>
 /// <param name="id">Client id</param>
 /// <param name="transactionId">Transaction id</param>
 public void CreatePayment(int id, string transactionId)
 {
     try
     {
         Payment payment = RentUnitOfWork.Payments.Get(id);
         payment.TransactionId = transactionId;
         payment.IsPaid        = true;
         RentUnitOfWork.Payments.Update(payment);
         RentUnitOfWork.Save();
     }
     catch (Exception e)
     {
         CreateLog(e, "ClientService", "CreatePayment");
     }
 }
コード例 #2
0
 /// <summary>
 /// Restore car.
 /// </summary>
 /// <param name="id">Car id</param>
 public void RestoreCar(int id)
 {
     try
     {
         Car car = RentUnitOfWork.Cars.Get(id);
         if (car != null)
         {
             car.IsDeleted = false;
             RentUnitOfWork.Cars.Update(car);
             RentUnitOfWork.Save();
         }
     }
     catch (Exception e)
     {
         CreateLog(e, "AdminService", "RestoreCar");
     }
 }
コード例 #3
0
 /// <summary>
 /// Confirm order.
 /// </summary>
 /// <param name="confirmDTO">Confirm object</param>
 public void ConfirmOrder(ConfirmDTO confirmDTO)
 {
     try
     {
         if (RentUnitOfWork.Orders.Get(confirmDTO.Order.Id).Confirm == null ||
             RentUnitOfWork.Orders.Get(confirmDTO.Order.Id).Confirm.Count == 0)
         {
             var confirm = RentMapperDTO.ToConfirm.Map <ConfirmDTO, Confirm>(confirmDTO);
             confirm.ManagerId = confirmDTO.User.Id;
             confirm.Order     = RentUnitOfWork.Orders.Get(confirmDTO.Order.Id);
             RentUnitOfWork.Confirms.Create(confirm);
             RentUnitOfWork.Save();
         }
     }
     catch (Exception e)
     {
         CreateLog(e, "ManagerService", "ConfirmOrder");
     }
 }
コード例 #4
0
 /// <summary>
 /// Make order.
 /// </summary>
 /// <param name="orderDTO">Order object</param>
 public void MakeOrder(OrderDTO orderDTO)
 {
     try
     {
         Order order = RentMapperDTO.ToOrder.Map <OrderDTO, Order>(orderDTO);
         order.Car      = RentUnitOfWork.Cars.Get(orderDTO.Car.Id);
         order.ClientId = orderDTO.Profile.Id;
         int price = ((int)(order.DateEnd - order.DateStart).TotalDays + 1) * order.Car.Price +
                     (orderDTO.WithDriver? ((int)(order.DateEnd - order.DateStart).TotalDays + 1) * 300 : 0);
         order.Payment = new[] { new Payment()
                                 {
                                     IsPaid = false, Price = price
                                 } };
         RentUnitOfWork.Orders.Create(order);
         RentUnitOfWork.Save();
     }
     catch (Exception e)
     {
         CreateLog(e, "ClientService", "MakeOrderAsync");
     }
 }
コード例 #5
0
 /// <summary>
 /// Return car after driving.
 /// </summary>
 /// <param name="returnDTO">Return object</param>
 public void ReturnCar(ReturnDTO returnDTO)
 {
     try
     {
         var order = RentUnitOfWork.Orders.Get(returnDTO.Order.Id);
         if ((order.Return == null || order.Return.Count == 0) && order.Confirm != null &&
             order.Confirm.Count > 0 && order.Confirm.First().IsConfirmed)
         {
             var returnCar = new Return();
             returnCar.ManagerId  = returnDTO.User.Id;
             returnCar.IsReturned = true;
             returnCar.Order      = RentUnitOfWork.Orders.Get(returnDTO.Order.Id);
             if (returnDTO.Crash != null)
             {
                 returnCar.Crash = new[]
                 {
                     new Crash()
                     {
                         Description = returnDTO.Crash.Description
                     }
                 };
                 returnCar.Crash.First().Payment = new[]
                 {
                     new Payment()
                     {
                         IsPaid = false,
                         Price  = returnDTO.Crash.Payment.Price
                     }
                 };
             }
             RentUnitOfWork.Returns.Create(returnCar);
             RentUnitOfWork.Save();
         }
     }
     catch (Exception e)
     {
         CreateLog(e, "ManagerService", "ReturnCar");
     }
 }
コード例 #6
0
        /// <summary>
        /// Update information about car.
        /// </summary>
        /// <param name="carDTO">Updated car</param>
        public void UpdateCar(CarDTO carDTO)
        {
            try
            {
                var oldCar = RentUnitOfWork.Cars.Get(carDTO.Id);

                var propert = oldCar.Properties.ToList();
                foreach (var i in propert)
                {
                    RentUnitOfWork.Properties.Delete(i.Id);
                }

                var imag = oldCar.Images.ToList();
                foreach (var i in imag)
                {
                    RentUnitOfWork.Images.Delete(i.Id);
                }

                oldCar.Properties.Clear();
                oldCar.Images.Clear();
                RentUnitOfWork.Save();

                if (carDTO.Brand.Name != oldCar.Brand.Name)
                {
                    Brand brand = RentUnitOfWork.Brands.Find(x => x.Name == carDTO.Brand.Name).FirstOrDefault();
                    if (brand == null)
                    {
                        brand = new Brand()
                        {
                            Name = carDTO.Brand.Name.Trim().ToLower().Replace("  ", " ")
                        };
                    }
                    oldCar.Brand = brand;
                }

                if (carDTO.Carcass.Type != oldCar.Carcass.Type)
                {
                    Carcass carcass = RentUnitOfWork.Carcasses.Find(x => x.Type == carDTO.Carcass.Type).FirstOrDefault();
                    if (carcass == null)
                    {
                        carcass = new Carcass()
                        {
                            Type = carDTO.Carcass.Type.Trim().ToLower().Replace("  ", " ")
                        };
                    }
                    oldCar.Carcass = carcass;
                }

                oldCar.Carrying     = carDTO.Carrying;
                oldCar.DateOfCreate = oldCar.DateOfCreate;
                oldCar.Doors        = carDTO.Doors;
                oldCar.EngineVolume = carDTO.EngineVolume;
                oldCar.Fuel         = carDTO.Fuel.Trim().ToLower().Replace("  ", " ");
                oldCar.Hoursepower  = carDTO.Hoursepower;
                oldCar.Model        = carDTO.Model.Trim().ToLower().Replace("  ", " ");
                oldCar.Number       = carDTO.Number.Trim().ToUpper().Replace("  ", " ");
                oldCar.Price        = carDTO.Price;

                if (carDTO.Quality.Text != oldCar.Quality.Text)
                {
                    Quality quality = RentUnitOfWork.Qualities.Find(x => x.Text == carDTO.Quality.Text).FirstOrDefault();
                    if (quality == null)
                    {
                        quality = new Quality()
                        {
                            Text = carDTO.Quality.Text.Trim().ToLower().Replace("  ", " ")
                        };
                    }
                    oldCar.Quality = quality;
                }

                if (carDTO.Transmission.Category != oldCar.Transmission.Category ||
                    carDTO.Transmission.Count != oldCar.Transmission.Count)
                {
                    Transmission transmission = RentUnitOfWork.Transmissions
                                                .Find(x => carDTO.Transmission.Category == x.Category && carDTO.Transmission.Count == x.Count)
                                                .FirstOrDefault();
                    if (transmission == null)
                    {
                        transmission = new Transmission()
                        {
                            Count    = carDTO.Transmission.Count,
                            Category = carDTO.Transmission.Category.Trim().ToLower().Replace("  ", " ")
                        };
                    }
                    oldCar.Transmission = transmission;
                }
                oldCar.Кoominess = carDTO.Кoominess;

                List <Property> properties = new List <Property>();
                foreach (var i in carDTO.Properties)
                {
                    Property property = new Property()
                    {
                        Name = i.Name.Trim().ToLower().Replace("  ", " "),
                        Text = i.Text.Trim().ToLower().Replace("  ", " ")
                    };
                    RentUnitOfWork.Properties.Create(property);
                    properties.Add(property);
                }

                oldCar.Properties = properties;

                List <Image> images = new List <Image>();
                foreach (var i in carDTO.Images)
                {
                    Image image = new Image()
                    {
                        Photo = i.Photo,
                        Text  = i.Text.Trim().ToLower().Replace("  ", " ")
                    };
                    RentUnitOfWork.Images.Create(image);
                    images.Add(image);
                }

                oldCar.Images = images;

                RentUnitOfWork.Cars.Update(oldCar);
                RentUnitOfWork.Save();
            }
            catch (Exception e)
            {
                CreateLog(e, "AdminService", "UpdateCar");
            }
        }
コード例 #7
0
        /// <summary>
        /// Create car.
        /// </summary>
        /// <param name="carDTO">New car</param>
        public void CreateCar(CarDTO carDTO)
        {
            try
            {
                Car car = RentMapperDTO.ToCar.Map <CarDTO, Car>(carDTO);
                car.Fuel   = car.Fuel.Trim().ToLower().Replace("  ", " ");
                car.Model  = car.Model.Trim().ToLower().Replace("  ", " ");
                car.Number = car.Number.Trim().ToUpper().Replace("  ", " ");

                Brand brand = RentUnitOfWork.Brands.Find(x => x.Name.ToLower()
                                                         .Replace(" ", "") == carDTO.Brand.Name.ToLower().Replace(" ", ""))?.FirstOrDefault();
                if (brand == null)
                {
                    brand = new Brand()
                    {
                        Name = carDTO.Brand.Name.Trim().ToLower().Replace("  ", " ")
                    };
                    RentUnitOfWork.Brands.Create(brand);
                }

                car.Brand = brand;

                Transmission transmission = RentUnitOfWork.Transmissions.Find(x => x.Category.ToLower()
                                                                              .Replace(" ", "") == carDTO.Transmission.Category.ToLower().Replace(" ", "") &&
                                                                              x.Count == carDTO.Transmission.Count)?.FirstOrDefault();
                if (transmission == null)
                {
                    transmission = new Transmission()
                    {
                        Category = carDTO.Transmission.Category.Trim()
                                   .ToLower().Replace("  ", " "), Count = carDTO.Transmission.Count
                    };
                    RentUnitOfWork.Transmissions.Create(transmission);
                }

                car.Transmission = transmission;

                Carcass carcass = RentUnitOfWork.Carcasses.Find(x => x.Type.ToLower()
                                                                .Replace(" ", "") == carDTO.Carcass.Type.ToLower().Replace(" ", ""))?.FirstOrDefault();
                if (carcass == null)
                {
                    carcass = new Carcass()
                    {
                        Type = carDTO.Carcass.Type.Trim().ToLower().Replace("  ", " ")
                    };
                    RentUnitOfWork.Carcasses.Create(carcass);
                }

                car.Carcass = carcass;

                Quality quality = RentUnitOfWork.Qualities.Find(x => x.Text.ToLower()
                                                                .Replace(" ", "") == carDTO.Quality.Text.ToLower().Replace(" ", ""))?.FirstOrDefault();
                if (quality == null)
                {
                    quality = new Quality()
                    {
                        Text = carDTO.Quality.Text.Trim().ToLower().Replace("  ", " ")
                    };
                    RentUnitOfWork.Qualities.Create(quality);
                }

                car.Quality = quality;

                List <Property> properties = new List <Property>();
                foreach (var i in carDTO.Properties)
                {
                    Property property = new Property()
                    {
                        Name = i.Name.Trim().ToLower()
                               .Replace("  ", " "), Text = i.Text.Trim().ToLower().Replace("  ", " ")
                    };
                    RentUnitOfWork.Properties.Create(property);
                    properties.Add(property);
                }

                car.Properties = properties;

                List <Image> images = new List <Image>();
                foreach (var i in carDTO.Images)
                {
                    Image image = new Image()
                    {
                        Photo = i.Photo, Text = i.Text.Trim().ToLower().Replace("  ", " ")
                    };
                    RentUnitOfWork.Images.Create(image);
                    images.Add(image);
                }

                car.Images = images;

                RentUnitOfWork.Cars.Create(car);
                RentUnitOfWork.Save();
            }
            catch (Exception e)
            {
                CreateLog(e, "AdminService", "CreateCar");
            }
        }