Example #1
0
        public IActionResult OrderCreationForm(OrderCreateViewModel model)
        {
            if (model.Tables == null)
            {
                model.Tables = new List <Table>();
            }
            var usrID    = HttpContext.Session.GetInt32("userID");
            var waiterId = _context.Users.Where(w => w.UserId == (int)usrID).Include(e => e.Employee).ThenInclude(w => w.Waiter).FirstOrDefault().Employee.Waiter.WaiterId;
            var table    = _context.Tables.Find(model.CurrentTable);

            model.Tables.Add(table);
            var order = new Order {
                Duration = 0, ManagedByWaiterId = waiterId, OrderDate = DateTime.Now, State = (int)OrderState.Created, Price = 0.0
            };

            _context.Add(order);
            _context.SaveChanges();

            foreach (var t in model.Tables)
            {
                var to = new TableOccupancy {
                    OrderId = order.OrderId, TableId = t.TableNum
                };
                _context.Add(to);
            }
            _context.SaveChanges();
            return(RedirectToAction("OrderList"));
        }
Example #2
0
        public IHttpActionResult PutMealIngredient(int id, MealIngredient mealIngredient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != mealIngredient.Id_MealIngredient)
            {
                return(BadRequest());
            }

            db.Entry(mealIngredient).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MealIngredientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #3
0
        // GET: Resturant
        public ActionResult Index()
        {
            //sql queries to update the database with up-to-date averages for overall ratings
            foreach (Restaurant item in db.restaurants.ToList())
            {
                if (db.Database.SqlQuery <Review>("Select * from Review Where RestCode = @iCode", new SqlParameter("@iCode", item.RestCode)).FirstOrDefault() != null)
                {
                    //overall rating
                    item.RestOverallRating = db.Database.SqlQuery <decimal>("Select Cast(Avg(ReviewOverallRating) AS Decimal(4,2)) From Review Where RestCode = @iCode", new SqlParameter("@iCode", item.RestCode)).FirstOrDefault();
                    //cleanliness rating
                    item.RestCleanliness = db.Database.SqlQuery <decimal>("Select Cast(Avg(ReviewCleanliness) AS Decimal(4,2)) From Review Where RestCode = @iCode", new SqlParameter("@iCode", item.RestCode)).FirstOrDefault();

                    //Date friendly
                    int    sum   = db.Database.SqlQuery <int>("Select Count(ReviewDateFriendly) From Review Where RestCode =  @iCode AND ReviewDateFriendly = 1", new SqlParameter("@iCode", item.RestCode)).FirstOrDefault();
                    int    count = db.Database.SqlQuery <int>("Select Count(ReviewDateFriendly) From Review Where RestCode =  @iCode", new SqlParameter("@iCode", item.RestCode)).FirstOrDefault();
                    double avg   = (double)sum / count;

                    if (avg > 0.5)
                    {
                        item.RestDateFriendly = true;
                    }
                    else
                    {
                        item.RestDateFriendly = false;
                    }

                    db.Entry(item).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            return(View(db.restaurants.ToList()));
        }
Example #4
0
        public IHttpActionResult PutFavorite(int id, Favorite favorite)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != favorite.Id)
            {
                return(BadRequest());
            }

            db.Entry(favorite).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FavoriteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public IActionResult AddReview(Review thisReview)
 {
     if (ModelState.IsValid)
     {
         Review newReview = new Review
         {
             Reviewer   = thisReview.Reviewer,
             Restaurant = thisReview.Restaurant,
             VisitedAt  = thisReview.VisitedAt,
             ReviewText = thisReview.ReviewText,
             Stars      = thisReview.Stars,
             Helpful    = 0,
             Unhelpful  = 0,
             CreatedAt  = DateTime.UtcNow,
             UpdatedAt  = DateTime.UtcNow
         };
         _context.Reviews.Add(newReview);
         _context.SaveChanges();
         return(RedirectToAction("Reviews"));
     }
     else
     {
         return(View("Index", thisReview));
     }
 }
Example #6
0
        public ActionResult Create([Bind(Include = "Id,Table")] Order order)
        {
            var orders = db.Order.Where(o => o.MealTime == null).ToList();

            order.WaiterId  = User.Identity.GetUserId();
            order.OrderTime = DateTime.Now;
            order.MealTime  = null;
            if (ModelState.IsValid)
            {
                foreach (var item in orders)
                {
                    if (order.Table == item.Table)
                    {
                        ViewBag.Error      = true;
                        ViewBag.TableError = true;
                        return(View(order));
                    }
                }
                try
                {
                    db.Order.Add(order);
                    db.SaveChanges();
                }
                catch
                {
                    ViewBag.Error = true;
                    return(View(order));
                }
                ViewBag.Error        = false;
                ViewBag.ZamowienieId = order.Id;
                return(View(order));
            }
            return(View(order));
        }
        public IActionResult add(int id)
        {
            //Do I have this item in the cart already
            foreach (Cart c in _context.MyCart.Include(i => i.CartItems))
            {
                foreach (CartItem ci in c.CartItems)
                {
                    if (ci.CartItemID == id)
                    {
                        //Up quantity
                        ci.Quantity++;
                        List <Cart> itemsa = _context.MyCart.Include(i => i.CartItems).ThenInclude(fi => fi.MenuItem).ToList <Cart>();
                        return(View("ShoppingCart", itemsa));
                    }
                }
            }
            //If not create new item
            var cartItem = new CartItem[]
            {
                new CartItem {
                    CartID = 1, MenuItemID = id, Quantity = 1
                }
            };

            foreach (CartItem ci in cartItem)
            {
                _context.CartItems.Add(ci);
            }
            _context.SaveChanges();

            //Return Shopping Cart View
            List <Cart> items = _context.MyCart.Include(i => i.CartItems).ToList <Cart>();

            return(View("ShoppingCart", items));
        }
        static void Main(string[] args)
        {
            //InsertMenuCategories();

            using var db = new RestaurantContext();

            var menuCategory = new MenuCategory
            {
                // Asume this data come from the UI
                Active      = true,
                DateCreated = DateTime.Today,
                ImageUrl    = "/somepath/foo.png",
                Name        = "Starters",
                Order       = 1
            };

            db.MenuCategories.Add(menuCategory);
            db.SaveChanges();

            // Asume menuItems is data coming from the UI that
            // we mapa into our model objects
            foreach (var menuItem in menuItems)
            {
                db.MenuItem.Add(new MenuItem
                {
                    Name        = menuItem.Name,
                    Description = menuItem.Description
                });
                db.SaveChanges();
            }

            //using var db = new RestaurantContext();
            var menuCategories = db.MenuCategories
                                 .Where(c => c.Active)
                                 .OrderBy(c => c.Order)
                                 .Select(c => new
            {
                c.Id,
                c.Name,
                MenuItems = c.MenuItems
                            .Select(i => new
                {
                    i.Name,
                    i.Description
                })
            })
                                 .ToList();

            foreach (var category in menuCategories)
            {
                Console.WriteLine($"Category: {category.Name}, Id: {category.Id}");
                int i = 1;
                foreach (var item in category.MenuItems)
                {
                    Console.WriteLine($"\t {i}.{item.Name}\n\t {item.Description}\n");
                    i++;
                }
            }
        }
Example #9
0
 public CustomerDTO Create(CustomerDTO obj, bool transactionEndpoint = true)
 {
     if (transactionEndpoint) _context.Database.BeginTransaction(IsolationLevel.Serializable);
     var added = CreateCustomer(obj);
     _context.SaveChanges();
     if (transactionEndpoint)_context.Database.CommitTransaction();
     return Converter.Convert(added.Entity);
 }
Example #10
0
        public void Create(ICategoryModel model)
        {
            Category item = new Category();

            item.Name = model.Name;
            _db.Categories.Add(item);
            _db.SaveChanges();
        }
Example #11
0
 public void Delete(OrderDetails orderDetails)
 {
     if (orderDetails != null)
     {
         db.OrderDetails.Remove(orderDetails);
         db.SaveChanges();
     }
 }
Example #12
0
 public void Delete(OrderProduct orderProduct)
 {
     if (orderProduct != null)
     {
         db.OrderProducts.Remove(orderProduct);
         db.SaveChanges();
     }
 }
 public void Delete(Restaurant restaurant)
 {
     if (restaurant != null)
     {
         db.Restaurants.Remove(restaurant);
         db.SaveChanges();
     }
 }
 public void Delete(Supplier supplier)
 {
     if (supplier != null)
     {
         db.Suppliers.Remove(supplier);
         db.SaveChanges();
     }
 }
Example #15
0
 public void Delete(User user)
 {
     if (user != null)
     {
         db.Users.Remove(user);
         db.SaveChanges();
     }
 }
Example #16
0
        public long AddRestaurant(AddRestaurantRequest addRestaurant)
        {
            var restaurant = mapper.Map <Restaurants>(addRestaurant);

            context.Add(restaurant);
            context.SaveChanges();
            return(restaurant.Id);
        }
 public void Delete(Stock stock)
 {
     if (stock != null)
     {
         db.Stock.Remove(stock);
         db.SaveChanges();
     }
 }
 public void Delete(Product product)
 {
     if (product != null)
     {
         db.Products.Remove(product);
         db.SaveChanges();
     }
 }
Example #19
0
        public async Task <ActionResult <BaseRespone> > PutMonAn(int id, [FromForm] MonAnRequest monAn)
        {
            //lấy dữ liệu cũ của món ăn
            var monan = await _context.MonAns.FindAsync(id);

            if (monan == null)
            {
                return(BadRequest());
            }

            if (monAn.File != null)
            {
                var uploadFilesPath = Path.Combine(_hostingEnvironment.WebRootPath, "Data\\sanpham");

                if (!Directory.Exists(uploadFilesPath))
                {
                    Directory.CreateDirectory(uploadFilesPath);
                }
                //lấy đường dẫn file cũ
                string oldImageName = _hostingEnvironment.WebRootPath + "\\Data\\sanpham\\" + monan.hinhanh;

                string newFileName = id + "_" + monAn.File.FileName;

                //lấy đường dẫn file mới
                string path = _hostingEnvironment.WebRootPath + "\\Data\\sanpham\\" + newFileName;

                //xóa file cũ
                if (monan.hinhanh != "")
                {
                    if (System.IO.File.Exists(oldImageName))
                    {
                        System.IO.File.Delete(oldImageName);
                    }
                }

                //lưu file mới
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    monAn.File.CopyTo(stream);
                    monan.hinhanh = newFileName;
                }
            }

            monan.tenmonan     = monAn.tenmonan;
            monan.dongia       = monAn.dongia;
            monan.trangthai    = monAn.trangthai;
            monan.noidung      = monAn.noidung;
            monan.id_loaimonan = monAn.id_loaimonan;

            _context.SaveChanges();

            return(new BaseRespone()
            {
                ErrorCode = 0
            });
        }
Example #20
0
        public void Create(ITableModel model)
        {
            Table item = new Table();

            item.NumberOfTable = model.NumberOfTable;
            item.AreaID        = model.AreaID;
            item.Occupied      = false;
            _db.Tables.Add(item);
            _db.SaveChanges();
        }
Example #21
0
        public void Create(IAreaModel model)
        {
            Area item = new Area()
            {
                Name = model.Name
            };

            _db.Areas.Add(item);
            _db.SaveChanges();
        }
Example #22
0
        public void Create(IProductModel model)
        {
            Product item = new Product();

            item.Name       = model.Name;
            item.CategoryID = model.CategoryID;
            item.Price      = model.Price;
            _db.Products.Add(item);
            _db.SaveChanges();
        }
Example #23
0
        public void Create(ISoldProductAccomplishedModel model)
        {
            SoldProductAccomplished item = new SoldProductAccomplished();

            item.Name       = model.Name;
            item.CategoryID = model.CategoryID;
            item.Price      = model.Price;
            _db.SoldProductsAccomplished.Add(item);
            _db.SaveChanges();
        }
Example #24
0
        public ActionResult Create([Bind(Include = "ProductId,ProductName,ProductDescription,ProductPrice")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Example #25
0
        public ActionResult Create([Bind(Include = "FoodId,Name,Description,Price,Type")] FoodItem foodItem)
        {
            if (ModelState.IsValid)
            {
                db.FoodItems.Add(foodItem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(foodItem));
        }
        public ActionResult Create([Bind(Include = "Id,Naam,VoedselType,Prijs,Btw_Tarief,Beschikbaar")] Voedsel voedsel)
        {
            if (ModelState.IsValid)
            {
                db.Voedsel.Add(voedsel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(voedsel));
        }
Example #27
0
        public ActionResult Create([Bind(Include = "ID,DepartmentName")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
Example #28
0
        public ActionResult Create([Bind(Include = "ID,Price,Type,Name,Description")] Item item)
        {
            if (ModelState.IsValid)
            {
                restaurantDb.Items.Add(item);
                restaurantDb.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
Example #29
0
        public ActionResult Create([Bind(Include = "RestaurantID,Title,CostRange")] Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                db.Restaurants.Add(restaurant);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(restaurant));
        }
        public ActionResult Create([Bind(Include = "CustomerId,FirstName,LastName")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Example #31
0
 public void SeatCustomer(DateTime when, int reservationId, List<byte> tables, int waiterId)
 {
     var availableSeats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);
     using (var context = new RestaurantContext())
     {
         List<string> errors = new List<string>();
         // Rule checking:
         // - Reservation must be in Booked status
         // - Table must be available - typically a direct check on the table, but proxied based on the mocked time here
         // - Table must be big enough for the # of customers
         var reservation = context.Reservations.Find(reservationId);
         if (reservation == null)
             errors.Add("The specified reservation does not exist");
         else if (reservation != null && reservation.ReservationStatus != Reservation.Booked)
             errors.Add("The reservation's status is not valid for seating. Only booked reservations can be seated.");
         var capacity = 0;
         foreach (var tableNumber in tables)
         {
             if (!availableSeats.Exists(x => x.Table == tableNumber))
                 errors.Add("Table " + tableNumber + " is currently not available");
             else
                 capacity += availableSeats.Single(x => x.Table == tableNumber).Seating;
         }
         if (capacity < reservation.NumberInParty)
             errors.Add("Insufficient seating capacity for number of customers. Alternate tables must be used.");
         if (errors.Count > 0)
             throw new BusinessRuleException("Unable to seat customer", errors);
         // 1) Create a blank bill with assigned waiter
         Bill seatedCustomer = new Bill()
         {
             BillDate = when,
             NumberInParty = reservation.NumberInParty,
             WaiterID = waiterId,
             ReservationID = reservation.ReservationID
         };
         context.Bills.Add(seatedCustomer);
         // 2) Add the tables for the reservation and change the reservation's status to arrived
         foreach (var tableNumber in tables)
             reservation.Tables.Add(context.Tables.Single(x => x.TableNumber == tableNumber));
         reservation.ReservationStatus = Reservation.Arrived;
         var updatable = context.Entry(context.Reservations.Attach(reservation));
         updatable.Property(x => x.ReservationStatus).IsModified = true;
         //updatable.Reference(x=>x.Tables).
         // 3) Save changes
         context.SaveChanges();
     }
     //string message = String.Format("Not yet implemented. Need to seat reservation {0} for waiter {1} at tables {2}", reservationId, waiterId, string.Join(", ", tables));
     //throw new NotImplementedException(message);
 }