示例#1
0
        public static bool UpdateClient(Client client)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbClient = context.Client.SingleOrDefault(x => x.Guid == client.Guid);
                if (dbClient == null)
                {
                    return(false);
                }

                dbClient.FirstName      = client.FirstName;
                dbClient.LastName       = client.LastName;
                dbClient.Patronymic     = client.Patronymic;
                dbClient.Birthday       = client.Birthday;
                dbClient.Phone          = client.Phone;
                dbClient.Email          = client.Email;
                dbClient.Password       = client.Password;
                dbClient.Sex            = client.Sex;
                dbClient.PassportNumber = client.PassportNumber;
                dbClient.PassportSeries = client.PassportSeries;
                dbClient.BankCard       = client.BankCard;
                dbClient.Login          = client.Login;
                dbClient.ImagePath      = client.ImagePath;

                context.SaveChanges();

                return(true);
            }
        }
示例#2
0
        public static Order GetOrder(Guid orderGuid)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbOrder = context.Order.SingleOrDefault(x => x.Guid == orderGuid);
                if (dbOrder == null)
                {
                    return(null);
                }

                return(new Order
                {
                    Guid = dbOrder.Guid,
                    ClientGuid = dbOrder.ClientOrders.First().ClientGuid,
                    Name = dbOrder.Name,
                    OrderDate = dbOrder.OrderDate.Value,
                    RentBeginDate = dbOrder.RentBeginDate.Value,
                    RentEndDate = dbOrder.RentEndDate.Value,
                    Status = (OrderStatus)dbOrder.StatusId,
                    PaymentType = (PaymentType)dbOrder.PaymentTypeId,
                    TotalCost = dbOrder.TotalCost.Value,
                    Area = new Area
                    {
                        Guid = dbOrder.Area.Guid,
                        Name = dbOrder.Area.Area1,
                        PriceMultiplier = dbOrder.Area.PriceMultiplier.Value
                    },
                    Car = DbCarWorker.ConstructCar(dbOrder.Car),
                    AdditonalServiceGuids = dbOrder.OrderAdditionalServices.Select(x => x.ServiceGuid).ToList()
                });
            }
        }
示例#3
0
        public static void UpdateCar(Car car)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbCar = context.Car.SingleOrDefault(x => x.Guid == car.Guid);
                if (dbCar == null)
                {
                    return;
                }

                dbCar.Guid           = car.Guid;
                dbCar.City           = car.City;
                dbCar.Color          = car.Color;
                dbCar.Mark           = car.Mark;
                dbCar.Mileage        = car.Mileage;
                dbCar.Model          = car.Model;
                dbCar.Photo          = car.Photo;
                dbCar.Price          = car.Price;
                dbCar.Status         = (int)car.Status;
                dbCar.Type           = car.Type;
                dbCar.YearProduction = car.YearProduction;

                context.SaveChanges();
            }
        }
示例#4
0
 public static bool CheckClient(string login)
 {
     using (var context = new Db.OpenRentEntities())
     {
         var dbClient = context.Client.SingleOrDefault(x => x.Login == login);
         return(dbClient != null);
     }
 }
示例#5
0
 public static Guid?SignIn(string login, string password)
 {
     using (var context = new Db.OpenRentEntities())
     {
         var dbClient = context.Client.SingleOrDefault(x => x.Login == login && x.Password == password);
         if (dbClient == null)
         {
             return(null);
         }
         return(dbClient.Guid);
     }
 }
 public static List<Area> GetAreaReference(string city)
 {
     using (var context = new Db.OpenRentEntities())
     {
         return context.Area.Where(x => x.City == city).Select(x => new Area
         {
             Guid = x.Guid,
             Name = x.Area1,
             PriceMultiplier = x.PriceMultiplier.Value
         }).OrderBy(x => x.Name).ToList();
     }            
 }
 public static List<AdditionalService> GetAdditionalServiceReference()
 {
     using (var context = new Db.OpenRentEntities())
     {
         return context.AdditionalServices.Select(x => new AdditionalService
         {
             Checked = false,
             Guid = x.Guid,
             Name = x.Name,
             Price = x.Price.Value
         }).OrderBy(x => x.Name).ToList();
     }
 }
示例#8
0
        public static Car GetCar(Guid carGuid)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbCar = context.Car.SingleOrDefault(x => x.Guid == carGuid);
                if (dbCar == null)
                {
                    return(null);
                }

                var car = ConstructCar(dbCar);
                return(car);
            }
        }
示例#9
0
        public static bool UpdateOrder(Order order)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbOrder = context.Order.SingleOrDefault(x => x.Guid == order.Guid);
                if (dbOrder == null)
                {
                    return(false);
                }

                dbOrder.Name          = order.Name;
                dbOrder.RentBeginDate = order.RentBeginDate;
                dbOrder.RentEndDate   = order.RentEndDate;
                dbOrder.TotalCost     = order.TotalCost;
                dbOrder.AreaGuid      = order.Area.Guid;
                dbOrder.PaymentTypeId = (int)order.PaymentType;

                var dbAddServices    = new List <Db.OrderAdditionalServices>();
                var dbRemoveServices = new List <Db.OrderAdditionalServices>();
                foreach (var dbService in dbOrder.OrderAdditionalServices)
                {
                    if (!order.AdditonalServiceGuids.Contains(dbService.ServiceGuid))
                    {
                        dbRemoveServices.Add(dbService);
                    }
                }
                foreach (var serviceGuid in order.AdditonalServiceGuids)
                {
                    if (dbOrder.OrderAdditionalServices.Count(x => x.ServiceGuid == serviceGuid) == 0)
                    {
                        dbAddServices.Add(new Db.OrderAdditionalServices {
                            Guid        = Guid.NewGuid(),
                            OrderGuid   = order.Guid,
                            ServiceGuid = serviceGuid
                        });
                    }
                }
                foreach (var dbRemoveService in dbRemoveServices)
                {
                    dbOrder.OrderAdditionalServices.Remove(dbRemoveService);
                    context.Entry(dbRemoveService).State = System.Data.Entity.EntityState.Deleted;
                }
                foreach (var dbAddService in dbAddServices)
                {
                    dbOrder.OrderAdditionalServices.Add(dbAddService);
                }

                return(true);
            }
        }
示例#10
0
        public static Client GetClient(string email, string password)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbClient = context.Client.SingleOrDefault(x => x.Email == email && x.Password == password);
                if (dbClient == null)
                {
                    return(null);
                }

                var client = ConstructClient(dbClient);
                return(client);
            }
        }
示例#11
0
        public static Client GetClient(Guid clientGuid)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbClient = context.Client.SingleOrDefault(x => x.Guid == clientGuid);
                if (dbClient == null)
                {
                    return(null);
                }

                var client = ConstructClient(dbClient);
                return(client);
            }
        }
示例#12
0
        private static List<ReferenceValue> GetReferenceValues(string name, string column, string search = "")
        {
            using (var context = new Db.OpenRentEntities())
            {
                var query = string.Format(@"SELECT Id, {1} FROM [Reference].[{0}]", name, column);
                if (!string.IsNullOrEmpty(search))
                {
                    query += string.Format(" WHERE {0}", search);
                }

                var reference = context.Database.SqlQuery<ReferenceValue>(query).OrderBy(x => x.Name).ToList();

                return reference;
            }
        }
示例#13
0
        public static void DeleteCar(Guid carGuid)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbCar = context.Car.SingleOrDefault(x => x.Guid == carGuid);
                if (dbCar == null)
                {
                    return;
                }

                context.Car.Remove(dbCar);
                context.Entry(dbCar).State = System.Data.Entity.EntityState.Deleted;
                context.SaveChanges();
            }
        }
示例#14
0
        public static List <OrderModel> GetClientOrders(Guid clientGuid)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbOrderGuids = context.ClientOrders.Where(x => x.ClientGuid == clientGuid).Select(x => x.OrderGuid).ToList();
                if (dbOrderGuids.Count == 0)
                {
                    return(new List <OrderModel>());
                }

                var dbOrders = context.Order.Where(x => dbOrderGuids.Contains(x.Guid)).OrderByDescending(x => x.OrderDate);
                var orders   = new List <OrderModel>();
                foreach (var dbOrder in dbOrders)
                {
                    orders.Add(new OrderModel
                    {
                        Guid         = dbOrder.Guid,
                        OrderDate    = dbOrder.OrderDate.Value.ToShortDateString(),
                        RentRange    = string.Format("{0} - {1}", dbOrder.RentBeginDate.Value.ToShortDateString(), dbOrder.RentEndDate.Value.ToShortDateString()),
                        Area         = dbOrder.Area.Area1,
                        PriceString  = dbOrder.TotalCost.ToString() + " рублей",
                        StatusString = ((OrderStatus)dbOrder.StatusId.Value).DescriptionAttr(),
                        ImagePath    = System.IO.Path.Combine(Settings.AttachedFiles ?? "", dbOrder.Car.Photo),
                        ServicesList = dbOrder.OrderAdditionalServices.Select(x => x.AdditionalServices.Name).OrderBy(x => x).ToList()

                                       //Guid = dbOrder.Guid,
                                       //Address = dbOrder.Address,
                                       //OrderDate = dbOrder.OrderDate.Value,
                                       //DeliveryDate = dbOrder.DeliveryDate.Value,
                                       //ExpirationDate = dbOrder.ExpirationDate.Value,
                                       //Status = (OrderStatus)dbOrder.Status,
                                       //Car = new Car
                                       //{
                                       //    Guid = dbOrder.Car.Guid,
                                       //    Model = dbOrder.Car.Model,
                                       //    Color = dbOrder.Car.Color,
                                       //    YearProduction = dbOrder.Car.YearProduction.Value,
                                       //    Photo = dbOrder.Car.Photo,
                                       //    Mileage = dbOrder.Car.Mileage.Value,
                                       //    Price = dbOrder.Car.Price.Value,
                                       //    Status = (CarStatus)dbOrder.Car.Status.Value
                                       //}
                    });
                }

                return(orders);
            }
        }
示例#15
0
 public static void AddClient(Client client)
 {
     using (var context = new Db.OpenRentEntities())
     {
         context.Client.Add(new Db.Client
         {
             Guid      = client.Guid,
             Email     = client.Email,
             Phone     = client.Phone,
             Login     = client.Login,
             Password  = client.Password,
             ImagePath = @"Users\default.png"
         });
         context.SaveChanges();
     }
 }
示例#16
0
        public static bool CancelOrder(Guid orderGuid)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbOrder = context.Order.SingleOrDefault(x => x.Guid == orderGuid);
                if (dbOrder == null)
                {
                    return(false);
                }

                dbOrder.StatusId = (int)OrderStatus.Canceled;
                context.SaveChanges();

                return(true);
            }
        }
示例#17
0
        public static bool DeleteOrder(Guid orderGuid)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbOrder = context.Order.SingleOrDefault(x => x.Guid == orderGuid);
                if (dbOrder == null)
                {
                    return(false);
                }

                context.Order.Remove(dbOrder);
                context.SaveChanges();

                return(true);
            }
        }
示例#18
0
        public static void AddCar(Car car)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbCar = new Db.Car
                {
                    Guid           = car.Guid,
                    City           = car.City,
                    Color          = car.Color,
                    Mark           = car.Mark,
                    Mileage        = car.Mileage,
                    Model          = car.Model,
                    Photo          = car.Photo,
                    Price          = car.Price,
                    Status         = (int)CarStatus.Free,
                    Type           = car.Type,
                    YearProduction = car.YearProduction
                };

                context.Car.Add(dbCar);
                context.SaveChanges();
            }
        }
示例#19
0
        public static bool AddOrder(Order order)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var dbOrder = new Db.Order
                {
                    Guid          = order.Guid,
                    Name          = order.Name,
                    OrderDate     = order.OrderDate,
                    RentBeginDate = order.RentBeginDate,
                    RentEndDate   = order.RentEndDate,
                    StatusId      = (int)OrderStatus.InProgressNotPaid,
                    PaymentTypeId = (int)order.PaymentType,
                    TotalCost     = order.TotalCost,
                    AreaGuid      = order.Area.Guid,
                    CarGuid       = order.Car.Guid,
                };
                dbOrder.ClientOrders.Add(new Db.ClientOrders {
                    Guid       = Guid.NewGuid(),
                    OrderGuid  = order.Guid,
                    ClientGuid = order.ClientGuid
                });
                foreach (var addServiceGuid in order.AdditonalServiceGuids)
                {
                    dbOrder.OrderAdditionalServices.Add(new Db.OrderAdditionalServices {
                        Guid        = Guid.NewGuid(),
                        OrderGuid   = order.Guid,
                        ServiceGuid = addServiceGuid
                    });
                }

                context.Order.Add(dbOrder);
                context.SaveChanges();

                return(true);
            }
        }
示例#20
0
        public static ObservableCollection <CarModel> GetCarsByFilter(Filter filter)
        {
            using (var context = new Db.OpenRentEntities())
            {
                var carModels = new ObservableCollection <CarModel>();

                var dbCars = context.Car.AsQueryable();
                if (!string.IsNullOrEmpty(filter.City))
                {
                    dbCars = dbCars.Where(x => x.City == filter.City);
                }
                if (!string.IsNullOrEmpty(filter.Model))
                {
                    dbCars = dbCars.Where(x => x.Model == filter.Model);
                }
                if (!string.IsNullOrEmpty(filter.Mark))
                {
                    dbCars = dbCars.Where(x => x.Mark == filter.Mark);
                }
                if (!string.IsNullOrEmpty(filter.Type))
                {
                    dbCars = dbCars.Where(x => x.Type == filter.Type);
                }
                if (filter.PriceFrom.HasValue)
                {
                    dbCars = dbCars.Where(x => x.Price >= filter.PriceFrom);
                }
                if (filter.PriceTo.HasValue)
                {
                    dbCars = dbCars.Where(x => x.Price <= filter.PriceTo);
                }

                if (filter.DateFrom.HasValue || filter.DateTo.HasValue)
                {
                    var dbActiveOrders = context.Order.Where(x => (x.StatusId.Value != (int)OrderStatus.Canceled) && (x.StatusId.Value != (int)OrderStatus.Complete));
                    if (filter.DateFrom.HasValue)
                    {
                        dbActiveOrders = dbActiveOrders.Where(x => filter.DateFrom.Value >= x.RentBeginDate || filter.DateFrom.Value <= x.RentEndDate);
                    }
                    if (filter.DateTo.HasValue)
                    {
                        dbActiveOrders = dbActiveOrders.Where(x => filter.DateTo.Value <= x.RentBeginDate || filter.DateTo.Value >= x.RentEndDate);
                    }
                    var dbOrderCarGuids = dbActiveOrders.Select(x => x.CarGuid).ToList();
                    dbCars = dbCars.Where(x => !dbOrderCarGuids.Contains(x.Guid));
                }

                foreach (var dbCar in dbCars)
                {
                    var carModel = new CarModel()
                    {
                        Guid           = dbCar.Guid,
                        IsEnabled      = (CarStatus)dbCar.Status.Value == CarStatus.Free,
                        ImagePath      = System.IO.Path.Combine(Settings.AttachedFiles ?? "", dbCar.Photo),
                        Model          = dbCar.Model,
                        Name           = string.Format("{0} {1} {2}", dbCar.Mark, dbCar.Model, dbCar.Type),
                        Price          = dbCar.Price.HasValue ? dbCar.Price.Value : 0,
                        YearProduction = dbCar.YearProduction.HasValue ? dbCar.YearProduction.Value : 0
                    };
                    carModels.Add(carModel);
                }

                return(carModels);
            }
        }