Exemplo n.º 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"));
        }
        public IActionResult ReviewInsertForm(Review rev)
        {
            ModelState.Remove("ReviewId");
            if (ModelState.IsValid)
            {
                rev.UserId     = (int)HttpContext.Session.GetInt32("userID");
                rev.ReviewDate = DateTime.Now;
                _context.Add(rev);
                _context.SaveChanges();

                return(Redirect("/User/ReviewsPage"));
            }
            ViewData["Rating"] = new SelectList(Review.digits, "Value", "Text");
            return(View(rev));
        }
Exemplo n.º 3
0
        public JsonResult Post([FromBody] Restaurant value)
        {
            try
            {
                using (var db = new RestaurantContext())
                {
                    db.Add(value);

                    if (!string.IsNullOrEmpty(value.Logo))
                    {
                        Utils.SaveFileFromBase64(value.LogoBase64, value.Logo, "logo");
                    }

                    db.SaveChanges();

                    return(Json(new Response {
                        Error = false, Description = "success", Result = new { Id = value.Id }
                    }));
                }
            }
            catch (Exception e)
            {
                return(Json(new Response {
                    Error = true, Description = e.Message
                }));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Image,Name,Surname,Phone,Position,DateOfBirth,Salary,HomeAddress,RestaurantId")] Employee employee)
        {
            var todaysDate = DateTime.Today;

            if ((todaysDate.Year - employee.DateOfBirth.Year) < 14)
            {
                ModelState.AddModelError("DateOfBirth", "Некорректна дата");
            }
            if (employee.Salary < 0)
            {
                ModelState.AddModelError("Salary", "Некорректна зарплата");
            }
            if (string.IsNullOrEmpty(employee.Name))
            {
                ModelState.AddModelError("Name", "Некорректне ім'я");
            }
            if (string.IsNullOrEmpty(employee.Surname))
            {
                ModelState.AddModelError("Surname", "Некорректне прізвище");
            }
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RestaurantId"] = new SelectList(_context.Restaurants, "Id", "Name", employee.RestaurantId);
            return(View(employee));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(int productId, [Bind("Id,Date,Price,Amount,ProviderId,ProductId,RestaurantId,Status,PlanReturn,FactReturn")] Order order)
        {
            order.ProductId = productId;
            var todayDate = DateTime.Now;

            if (order.Date > todayDate)
            {
                ModelState.AddModelError("Date", "Некорректна дата");
            }
            if (order.PlanReturn < order.Date)
            {
                ModelState.AddModelError("PlanReturn", "Некорректна дата повернення");
            }
            if (order.Amount <= 0)
            {
                ModelState.AddModelError("Amount", "Некорректна кількість");
            }
            if (order.Price < 0)
            {
                ModelState.AddModelError("Price", "Некорректна вартість");
            }

            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Orders", new { Id = productId, name = _context.Products.Where(p => p.Id == productId).FirstOrDefault().Name }));
                //_context.Products.Where(p => p.Id == id).FirstOrDefault().Name });
            }
            //   ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Id", order.ProductId);
            ViewData["ProviderId"]   = new SelectList(_context.Providers, "Id", "Address", order.ProviderId);
            ViewData["RestaurantId"] = new SelectList(_context.Restaurants, "Id", "Address", order.RestaurantId);
            return(RedirectToAction("Index", "Orders", new { Id = productId, name = _context.Products.Where(p => p.Id == productId).FirstOrDefault().Name }));
        }
Exemplo n.º 6
0
        public long AddRestaurant(AddRestaurantRequest addRestaurant)
        {
            var restaurant = mapper.Map <Restaurants>(addRestaurant);

            context.Add(restaurant);
            context.SaveChanges();
            return(restaurant.Id);
        }
Exemplo n.º 7
0
        public IActionResult addRev(Restaurant newRev)
        {
            _context.Add(newRev);
            _context.SaveChanges();


            return(RedirectToAction("Show"));
        }
Exemplo n.º 8
0
 public IActionResult CreateReview(Review review)
 {
     System.Console.WriteLine(review);
     review.CreatedAt = DateTime.Now;
     review.UpdatedAt = DateTime.Now;
     _context.Add(review);
     _context.SaveChanges();
     return(RedirectToAction("Reviews"));
 }
Exemplo n.º 9
0
 public ActionResult <JobApplication> Create(JobApplication jobApplication)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _context.Add(jobApplication);
     _context.SaveChanges();
     return(CreatedAtAction(nameof(GetById), new { id = jobApplication.Id }, jobApplication));
 }
Exemplo n.º 10
0
        public IActionResult Create(Person NewPerson)
        {
            NewPerson.created_at = DateTime.Now;
            NewPerson.updated_at = DateTime.Now;

            _context.Add(NewPerson);
            // OR _context.Users.Add(NewPerson);
            _context.SaveChanges();
            return(RedirectToAction("List"));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,Phone")] Provider provider)
        {
            if (string.IsNullOrEmpty(provider.Name))
            {
                ModelState.AddModelError("Name", "Некорректне ім'я");
            }
            if (string.IsNullOrEmpty(provider.Address))
            {
                ModelState.AddModelError("Address", "Некорректна адреса");
            }
            if (ModelState.IsValid)
            {
                _context.Add(provider);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(provider));
        }
Exemplo n.º 12
0
 public ActionResult <OrderTable> Create(OrderTable orderTable)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _context.Add(orderTable);
     _context.SaveChanges();
     return(CreatedAtAction(nameof(GetById), new { id = orderTable.Id }, orderTable));
 }
Exemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("Id_dato,Nombre,Apellido,Direccion,Eliminacion")] tbl_Datos tbl_Datos)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tbl_Datos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tbl_Datos));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,Phone,Site,GeoLong,GeoLat")] Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                _context.Add(restaurant);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(restaurant));
        }
        public async Task <IActionResult> Create([Bind("Id_votacion,Id_restaurante,Id_dato,Votacion")] tbl_Votaciones tbl_Votaciones)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tbl_Votaciones);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tbl_Votaciones));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Create([Bind("ID,OwnerName,Adress")] Owners owners)
        {
            if (ModelState.IsValid)
            {
                _context.Add(owners);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(owners));
        }
        public async Task <IActionResult> Create([Bind("Id_usuario,Id_dato,Id_rol,Usuario,Clave,Estado")] tbl_Usuarios tbl_Usuarios)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tbl_Usuarios);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tbl_Usuarios));
        }
        public async Task <IActionResult> Create([Bind("Id_restaurante,Nombre,Descripcion,Direccion,H_apertura,H_cierre,Logo,Imagen_item")] tbl_Restaurantes tbl_Restaurantes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tbl_Restaurantes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tbl_Restaurantes));
        }
Exemplo n.º 19
0
 internal EntityEntry<Customer> CreateCustomer(CustomerDTO obj)
 {
     var customer = Converter.Convert(obj);
     var zipresolution = _context.ZipId.FirstOrDefault(zip =>
         zip.ZipCode.Equals(customer.Person.Location.ZipCodeNavigation.ZipCode));
     if (zipresolution != null)
     {
         customer.Person.Location.ZipCodeNavigation = zipresolution;
     }
     return _context.Add(customer);
 }
        public async Task <IActionResult> Create([Bind("PlateID,Name,Ingredients,Price,Serves")] Plate plate)
        {
            if (ModelState.IsValid)
            {
                _context.Add(plate);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(plate));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Address,City,State,Phone,OwnerName,RegistrationDate")] Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                _context.Add(restaurant);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(restaurant));
        }
        public async Task <IActionResult> Create([Bind("Id_rol,Rol,Descripcion")] tbl_Roles tbl_Roles)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tbl_Roles);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tbl_Roles));
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Create([Bind("ReservationId,TableId,ReserveDate")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reservation);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "RestaurantTables"));
            }
            return(View(reservation));
        }
Exemplo n.º 24
0
        public async Task <IActionResult> Create([Bind("ProductName,Description,ImagePath,UnitPrice,CategoryID")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryName", product.CategoryID);
            return(View(product));
        }
Exemplo n.º 25
0
 public IActionResult createReview(Restaurant newRestaurant)
 {
     if (ModelState.IsValid)
     {
         _context.Add(newRestaurant);
         _context.SaveChanges();
         return(RedirectToAction("Review"));
     }
     else
     {
         return(View("Index"));
     }
 }
Exemplo n.º 26
0
        public async Task <IActionResult> Create([Bind("Id,Image,Name,Type,Weight,Price,Remarks,RestaurantId")] Dish dish)
        {
            //  dish.RestaurantId =restaurantId;
            if (ModelState.IsValid)
            {
                _context.Add(dish);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));//"Index", "Dishes", new { id = restaurantId, name = _context.Restaurants.Where(e => e.Id == restaurantId).FirstOrDefault().Name }) ;
            }
            ViewData["RestaurantId"] = new SelectList(_context.Restaurants, "Id", "Name");
            return(View(dish));//RedirectToAction("Index", "Dishes", new { id = restaurantId, name = _context.Restaurants.Where(e => e.Id == restaurantId).FirstOrDefault().Name });
        }
Exemplo n.º 27
0
 public IActionResult AddReview(Review submittedReview)
 {
     if (ModelState.IsValid)
     {
         _context.Add(submittedReview);
         _context.SaveChanges();
         return(RedirectToAction("Success"));
     }
     else
     {
         return(View("Index"));
     }
 }
Exemplo n.º 28
0
 public IActionResult Create(Review review)
 {
     if (ModelState.IsValid)
     {
         _context.Add(review);
         _context.SaveChanges();
         return(RedirectToAction("Reviews"));
     }
     else
     {
         // Oh no!  We need to return a ViewResponse to preserve the ModelState, and the errors it now contains!
         return(View("Index"));
     }
 }
Exemplo n.º 29
0
        /*
         * Category Controller with all the methods that interact with the Restaurant table. (Restaurant = user)
         *  Methods are seperated and ordered by CRUD functionalities (Create, read, update, delete)
         *  This was created with the future in mind where users will be able to create update and delete their own categories.
         */

        // CREATE
        public void CreateCategory(string catName, string username)
        {
            Restaurant theUser = RestaurantController.GetResByUsername(username);

            using (RestaurantContext context = new RestaurantContext())
            {
                Category newCategory = new Category()
                {
                    Name         = catName,
                    RestaurantID = theUser.ID
                };
                context.Add(newCategory);
                context.SaveChanges();
            }
        }
Exemplo n.º 30
0
        public static void AddDishToRestaurant(string restName, string dishName)
        {
            var restRepo = new RestaurantsRepository();
            var rest     = restRepo.FindBy(m => m.Name.StartsWith(restName)).FirstOrDefault();

            var dishRepo = new SignatureDishesRepository();
            var dish     = dishRepo.FindBy(b => b.Name.StartsWith(dishName)).FirstOrDefault();

            var context = new RestaurantContext();

            context.Add(new RestaurantSignatureDish {
                SignatureDishId = dish.Id, RestaurantId = rest.Id
            });
            context.SaveChanges();
        }