Esempio n. 1
0
        public void UpdateOrder(Order oldOrder, Order newOrder)
        {
            using (var db = new HotelServicesDbContext())
            {
                if (oldOrder == null || newOrder == null)
                {
                    return;
                }

                var ord = db.Orders.FirstOrDefault(o => o.Id == oldOrder.Id);
                if (ord == null)
                {
                    return;
                }

                ord.Id        = newOrder.Id;
                ord.Cost      = newOrder.Cost;
                ord.IsPaid    = newOrder.IsPaid;
                ord.OrderDate = newOrder.OrderDate;
                ord.Service   = db.ServiceInfos.FirstOrDefault(s => s.Id == newOrder.Service.Id);
                ord.Units     = newOrder.Units;
                ord.User      = db.Users.FirstOrDefault(u => u.Id == newOrder.User.Id);

                db.SaveChanges();
            }
        }
        public void UpdateService(ServiceInfo oldService, ServiceInfo newService)
        {
            using (var db = new HotelServicesDbContext())
            {
                if (oldService == null || newService == null)
                {
                    return;
                }

                var ord = db.ServiceInfos.FirstOrDefault(o => o.Id == oldService.Id);
                if (ord == null)
                {
                    return;
                }

                ord.IsDeprecated = true;
                db.ServiceInfos.Add(newService);
                db.SaveChanges();
            }

            //using (var db = new HotelServicesDbContext())
            //{
            //    newService.IsDeprecated = false;
            //    db.ServiceInfos.Add(newService);
            //    db.SaveChanges();
            //}
        }
 public void RemoveUser(User user)
 {
     if (user == null)
     {
         return;
     }
     using (var db = new HotelServicesDbContext())
     {
         db.Users.Remove(user);
         db.SaveChanges();
     }
 }
 public void AddUser(User user)
 {
     if (user == null)
     {
         return;
     }
     using (var db = new HotelServicesDbContext())
     {
         user.Role = db.Roles.FirstOrDefault(r => r.Id == user.Role.Id);
         db.Users.Add(user);
         db.SaveChanges();
     }
 }
Esempio n. 5
0
        public void RemoveOrder(Order order)
        {
            if (order == null)
            {
                return;
            }

            using (var db = new HotelServicesDbContext())
            {
                db.Orders.Remove(order);
                db.SaveChanges();
            }
        }
        public void RemoveServiceInfo(ServiceInfo service)
        {
            if (service == null)
            {
                return;
            }

            using (var db = new HotelServicesDbContext())
            {
                db.ServiceInfos.Remove(service);
                db.SaveChanges();
            }
        }
Esempio n. 7
0
        public void AddOrder(Order order)
        {
            if (order == null)
            {
                return;
            }

            using (var db = new HotelServicesDbContext())
            {
                order.User.Role = db.Roles.FirstOrDefault(r => r.Id == order.User.Role.Id);
                order.User      = db.Users.FirstOrDefault(u => u.Id == order.User.Id);
                order.Service   = db.ServiceInfos.FirstOrDefault(s => s.Id == order.Service.Id);

                db.Orders.Add(order);
                db.SaveChanges();
            }
        }