Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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();
     }
 }
Exemplo n.º 7
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();
            }
        }
Exemplo n.º 8
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);
            }
        }