Esempio n. 1
0
        public ActionResult AddResaurant(RestaurantModel model)
        {
            try
            {
                using (isadbEntities context = new isadbEntities())
                {
                    if (ModelState.IsValid)
                    {
                        Restaurant restaurant = new Restaurant
                        {
                            Location  = CreatePoint(model.Latitude, model.Longitude),
                            ManagerId = model.ManagerId,
                            Name      = model.Name
                        };
                        context.Restaurants.Add(restaurant);
                        context.SaveChanges();
                        for (int i = 0; i < 5; i++)
                        {
                            Table t = new Table
                            {
                                local_number  = i + 1,
                                restaurant_id = restaurant.Id
                            };
                            context.Tables.Add(t);
                        }
                        context.SaveChanges();
                        return(RedirectToAction("Index"));
                    }

                    else
                    {
                        List <SelectListItem> users = context.Users.Where(x => x.AspNetUser.AspNetRoles.Any(z => z.Name.Equals("manager"))).Select(x => new SelectListItem
                        {
                            Text  = x.FirstName + " " + x.LastName,
                            Value = x.Id.ToString()
                        }).ToList();
                        model          = new RestaurantModel();
                        model.Managers = users;

                        return(View(model));
                    }
                }
            }
            catch (Exception)
            {
                model          = new RestaurantModel();
                model.Managers = new List <SelectListItem>();
            }
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult AddMenu(MenuModel model)
        {
            try
            {
                using (isadbEntities context = new isadbEntities())
                {
                    if (ModelState.IsValid)
                    {
                        FoodManu menu = new FoodManu
                        {
                            Description  = model.Descriptiom,
                            Name         = model.Name,
                            Price        = model.Price,
                            RestaurantId = model.RestaurantId
                        };
                        context.FoodManus.Add(menu);
                        context.SaveChanges();

                        return(RedirectToAction("Menu", new { id = model.RestaurantId }));
                    }

                    else
                    {
                        return(View(model));
                    }
                }
            }
            catch (Exception)
            {
            }
            return(View(model));
        }
Esempio n. 3
0
        public ActionResult Reservation(ReservationModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (isadbEntities context = new isadbEntities())
                    {
                        Table table = context.Tables.Find(model.Id);
                        bool  isEnableReservation = !table.Reservations.Any() || !table.Reservations.Any(x => !(x.Date_from > model.DateTo || x.Date_to < model.DateFrom));
                        //Any(x => x.Date_to < model.DateTo && x.Date_from > model.DateFrom);
                        if (isEnableReservation)
                        {
                            string      aspUserId   = User.Identity.GetUserId();
                            User        user        = context.Users.FirstOrDefault(x => x.AspUserId == aspUserId);
                            Reservation reservation = new Reservation
                            {
                                Table_id  = model.Id,
                                Date_from = model.DateFrom,
                                Date_to   = model.DateTo,
                                User_id   = user.Id
                            };

                            context.Reservations.Add(reservation);
                            context.SaveChanges();

                            return(RedirectToAction("RestaurantDetail", new { id = context.Tables.Find(model.Id).restaurant_id }));
                        }
                        else
                        {
                            List <string> reservations = new List <string>();

                            reservations = context.Tables.Find(model.Id).Reservations.Where(x => x.Date_to > DateTime.Now).Select(x => x.Date_from.ToString() + " - " + x.Date_to.ToString()).ToList();


                            model.Reservations = reservations;

                            ModelState.AddModelError("NotEnable", "Table is not enabled for selected period");
                            return(View(model));
                        }
                    }
                }
                else
                {
                    return(View(model));
                }
            }
            catch (Exception)
            {
                List <string> reservations = new List <string>();
                using (isadbEntities context = new isadbEntities())
                {
                    reservations = context.Tables.Find(model.Id).Reservations.Where(x => x.Date_to > DateTime.Now).Select(x => x.Date_from.ToString() + " - " + x.Date_to.ToString()).ToList();
                }
                model.Reservations = reservations;
                return(View(model));
            }
        }
Esempio n. 4
0
        public ActionResult RestaurantDelete(long id)
        {
            try
            {
                using (isadbEntities context = new isadbEntities())
                {
                    Restaurant r = context.Restaurants.Find(id);
                    context.Restaurants.Remove(r);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public async Task <ActionResult> RegisterManager(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    using (isadbEntities context = new isadbEntities())
                    {
                        User newUser = new User
                        {
                            FirstName = model.FirstName,
                            LastName  = model.LastName,
                            Address   = model.Address,
                            AspUserId = user.Id
                        };

                        var aspUser = context.AspNetUsers.Find(user.Id);
                        var role    = context.AspNetRoles.Find("47b9de90-d193-482d-90ad-08efee65a47c");
                        aspUser.AspNetRoles.Add(role);
                        context.Users.Add(newUser);
                        context.SaveChanges();
                    }

                    return(RedirectToAction("Index", "Manager"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 6
0
        public ActionResult EditResaurant(RestaurantModel model)
        {
            try
            {
                using (isadbEntities context = new isadbEntities())
                {
                    if (ModelState.IsValid)
                    {
                        Restaurant restaurant = context.Restaurants.Find(model.Id);

                        restaurant.Location  = CreatePoint(model.Latitude, model.Longitude);
                        restaurant.ManagerId = model.ManagerId;
                        restaurant.Name      = model.Name;

                        context.SaveChanges();
                        return(RedirectToAction("Index"));
                    }

                    else
                    {
                        List <SelectListItem> users = context.Users.Where(x => x.AspNetUser.AspNetRoles.Any(z => z.Name.Equals("manager"))).Select(x => new SelectListItem
                        {
                            Text  = x.FirstName + " " + x.LastName,
                            Value = x.Id.ToString()
                        }).ToList();
                        model          = new RestaurantModel();
                        model.Managers = users;

                        return(View(model));
                    }
                }
            }
            catch (Exception)
            {
                model          = new RestaurantModel();
                model.Managers = new List <SelectListItem>();
            }
            return(View(model));
        }