public ActionResult Order(FoodOrderView foodOrderView)
        {
            CateringContext cateringContext = new CateringContext();

            if (foodOrderView.NumberInOrder < 0)
            {
                return(View("FoodPage"));
            }
            foreach (var f in cateringContext.currentOrders)
            {
                if (f.FoodName == foodOrderView.FoodName)
                {
                    cateringContext.currentOrders.Remove(f);
                }
            }

            cateringContext.currentOrders.Add(new CurrentOrder
            {
                FoodName      = foodOrderView.FoodName,
                Price         = foodOrderView.Price,
                NumberInOrder = foodOrderView.NumberInOrder
            });

            cateringContext.SaveChanges();



            return(RedirectToAction("FoodPage"));
        }
Beispiel #2
0
        public ActionResult Plate(TransactionViewModel model)
        {
            if (model.Address == null || model.ID_Card_Number == null || model.ID_Card_Series == null)
            {
                return(RedirectToAction("Plate"));
            }
            Transaction transaction = new Transaction();

            transaction.TotalCost      = model.TotalCost;
            transaction.ID_Card_Number = model.ID_Card_Number;
            transaction.ID_Card_Series = model.ID_Card_Series;
            transaction.Address        = model.Address;
            transaction.Date           = DateTime.Now;

            if (Request.IsAuthenticated)
            {
                transaction.Email    = model.Email;
                transaction.ClientId = model.ClientId;

                foreach (var food in db.currentOrders)
                {
                    if (food.NumberInOrder > 0)
                    {
                        db.TransactionToFoods.Add(new TransactionToFood
                        {
                            Number        = food.NumberInOrder,
                            FoodName      = food.FoodName,
                            TransactionId = transaction.Id
                        });
                    }

                    db.currentOrders.Remove(food);
                }
            }
            else
            {
                transaction.Email = "*****@*****.**";
                CateringContext ct = new CateringContext();

                foreach (var food in db.currentOrders)
                {
                    if (food.NumberInOrder > 0)
                    {
                        db.TransactionToFoods.Add(new TransactionToFood
                        {
                            Number        = food.NumberInOrder,
                            FoodName      = food.FoodName,
                            TransactionId = transaction.Id
                        });
                    }

                    db.currentOrders.Remove(food);
                }
            }

            db.transactions.Add(transaction);
            db.SaveChanges();
            return(RedirectToAction("PostOrder"));
        }
Beispiel #3
0
        public UnitOfWork()
        {
            db = new CateringContext();

            Notifications = new BaseRepository <Notification, int>(db);
            Products      = new BaseRepository <Product, int>(db);
            FoodShoppings = new BaseRepository <ShoppingCart, string>(db);
        }
Beispiel #4
0
        public TransactionViewModel GetTransactionViewModel(Transaction transaction, int id)
        {
            TransactionViewModel NewModel = new TransactionViewModel();

            var Result = from Food in cateringContext.foods
                         select new
            {
                Food.FoodName,
                Food.Price,
                Food.Quantity,
                Numbered = (from food in cateringContext.TransactionToFoods
                            where (food.FoodName == Food.FoodName)
                            & (food.TransactionId == id)
                            select food
                            ).Count()
            };

            var NewTransactionViewModel = new TransactionViewModel();

            NewTransactionViewModel.Address        = transaction.Address;
            NewTransactionViewModel.ClientId       = transaction.ClientId;
            NewTransactionViewModel.Email          = transaction.Email;
            NewTransactionViewModel.ID_Card_Number = transaction.ID_Card_Number;
            NewTransactionViewModel.ID_Card_Series = transaction.ID_Card_Series;

            var NumberedList = new List <NumberedViewModel>();

            int totalCost = 0;

            foreach (var food in Result)
            {
                CateringContext context = new CateringContext();
                int             nr      = 0;
                if (food.Numbered > 0)
                {
                    nr = context.TransactionToFoods.First(a => a.FoodName == food.FoodName && a.TransactionId == id).Number;
                }
                NumberedList.Add(new NumberedViewModel()
                {
                    Name   = food.FoodName,
                    Number = nr,
                    Price  = food.Price
                }
                                 );
                totalCost += nr * food.Price;
            }

            transaction.TotalCost = totalCost;

            NewTransactionViewModel.TotalCost = totalCost;
            NewTransactionViewModel.Foods     = NumberedList;

            return(NewTransactionViewModel);
        }
        private FoodOrderView getView(Food food)
        {
            FoodOrderView foodOrderView = new FoodOrderView();

            foodOrderView.FoodName        = food.FoodName;
            foodOrderView.FoodIngredients = food.FoodIngredients;
            foodOrderView.ImageLink       = food.ImageLink;
            foodOrderView.Price           = food.Price;
            foodOrderView.Quantity        = food.Quantity;
            foodOrderView.FoodType        = food.FoodType;

            CateringContext cateringContext = new CateringContext();

            if (Request.IsAuthenticated)
            {
                foodOrderView.NumberInOrder = 0;
                foreach (var f in cateringContext.currentOrders)
                {
                    if (f.FoodName == food.FoodName)
                    {
                        foodOrderView.NumberInOrder = f.NumberInOrder;
                        break;
                    }
                }
            }
            else
            {
                HttpCookieCollection MyCookieColl = Request.Cookies;
                HttpCookie           MyCookie;

                String[]        arr1    = MyCookieColl.AllKeys;
                CateringContext context = new CateringContext();

                for (int i = 0; i < arr1.Length; i++)
                {
                    MyCookie = MyCookieColl[arr1[i]];
                    if (MyCookie.Name == food.FoodName)
                    {
                        if (Int32.TryParse(MyCookie.Value, out int temp) == true)
                        {
                            foodOrderView.NumberInOrder = Int32.Parse(MyCookie.Value);
                            break;
                        }
                    }
                }
            }


            return(foodOrderView);
        }
        public ActionResult Order(string FoodName)
        {
            CateringContext db      = new CateringContext();
            Food            newFood = new Food();

            foreach (var f in db.foods)
            {
                if (f.FoodName == FoodName)
                {
                    newFood = f;
                }
            }

            return(View(getView(newFood)));
        }
Beispiel #7
0
 public MenusController(CateringContext context)
 {
     _context = context;
 }
Beispiel #8
0
 public UnitOfWork()
 {
     Context = new CateringContext();
 }
Beispiel #9
0
 public CateringOrderRepository()
 {
     _ctx = new CateringContext();
 }
Beispiel #10
0
 public WaiterRepository()
 {
     _ctx = new CateringContext();
 }
Beispiel #11
0
 public BaseRepository(CateringContext db)
 {
     _db = db;
 }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            CateringContext db = new CateringContext();

            foreach (var client in db.Clients)
            {
                if (client.Email == model.Email)
                {
                    if (client.isSuspended)
                    {
                        ModelState.AddModelError("", "User " + client.FirstName + " is suspended");
                        return(View(model));
                    }
                }
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            //We get the user who has attempted to logged in
            var user = await UserManager.FindAsync(model.Email, model.Password);

            switch (result)
            {
            //If the login was a success, we get the user's role, the datetime of the login and his email, and add it to the login logs data table
            case SignInStatus.Success:
                CateringContext contet = new CateringContext();
                foreach (var food in contet.currentOrders)
                {
                    contet.currentOrders.Remove(food);
                }
                contet.SaveChanges();


                string role;

                if (UserManager.IsInRole(user.Id, "Admin"))
                {
                    role = "Admin";
                }
                else
                {
                    role = "User";
                }

                var LoginModel = new LoginLogsModels
                {
                    LoginDate = DateTime.Now,
                    UserRole  = role,
                    UserEmail = model.Email
                };

                db.loginLogs.Add(LoginModel);

                HttpCookieCollection MyCookieColl = Request.Cookies;
                HttpCookie           MyCookie;

                String[]        arr1    = MyCookieColl.AllKeys;
                CateringContext context = new CateringContext();

                for (int i = 0; i < arr1.Length; i++)
                {
                    MyCookie = MyCookieColl[arr1[i]];
                    int  price = 0;
                    bool ok    = false;

                    if (MyCookie.Value == null)
                    {
                        continue;
                    }

                    foreach (var food in db.foods)
                    {
                        if (food.FoodName == MyCookie.Name)
                        {
                            price            = food.Price;
                            ok               = true;
                            MyCookie.Expires = DateTime.Now.AddDays(-1);
                        }
                    }
                    if (ok == false)
                    {
                        continue;
                    }
                    if (Int32.TryParse(MyCookie.Value, out int temp) == false)
                    {
                        continue;
                    }

                    context.currentOrders.Add(new CurrentOrder
                    {
                        FoodName      = MyCookie.Name,
                        Price         = price,
                        NumberInOrder = Int32.Parse(MyCookie.Value)
                    });

                    MyCookie.Expires = DateTime.Now.AddDays(-1);
                }

                context.SaveChanges();
                db.SaveChanges();
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationDbContext context = new ApplicationDbContext();
                var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

                //var user = new ApplicationUser { UserName = model.Email, Email = model.Email };

                var user = new ApplicationUser
                {
                    UserName       = model.Email,
                    Email          = model.Email,
                    ID_Card_Number = model.IDCardNumber,
                    CNP            = model.CNP,
                    ID_Card_Series = model.IDCardSeries,
                    Address        = model.Address,
                    PhoneNumber    = model.TelephoneNumber,
                };

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

                if (result.Succeeded)
                {
                    CateringContext contet = new CateringContext();
                    foreach (var food in contet.currentOrders)
                    {
                        contet.currentOrders.Remove(food);
                    }
                    contet.SaveChanges();

                    UserManager.AddToRole(user.Id, "User");

                    CateringContext db     = new CateringContext();
                    var             client = new Client
                    {
                        FirstName       = model.FirstName,
                        LastName        = model.LastName,
                        Email           = model.Email,
                        ID_Card_Number  = model.IDCardNumber,
                        ID_Card_Series  = model.IDCardSeries,
                        Password        = model.Password,
                        CNP             = model.CNP,
                        Address         = model.Address,
                        TelephoneNumber = model.TelephoneNumber,
                        ClientId        = user.Id
                    };

                    db.Clients.AddOrUpdate(client);

                    HttpCookieCollection MyCookieColl = Request.Cookies;
                    HttpCookie           MyCookie;

                    String[] arr1 = MyCookieColl.AllKeys;

                    for (int i = 0; i < arr1.Length; i++)
                    {
                        MyCookie = MyCookieColl[arr1[i]];
                        int  price = 0;
                        bool ok    = false;

                        if (MyCookie.Value == null)
                        {
                            continue;
                        }

                        foreach (var food in db.foods)
                        {
                            if (food.FoodName == MyCookie.Name)
                            {
                                price            = food.Price;
                                ok               = true;
                                MyCookie.Expires = DateTime.Now.AddDays(-1);
                            }
                        }
                        if (ok == false)
                        {
                            continue;
                        }
                        if (Int32.TryParse(MyCookie.Value, out int temp) == false)
                        {
                            continue;
                        }

                        db.currentOrders.Add(new CurrentOrder
                        {
                            FoodName      = MyCookie.Name,
                            Price         = price,
                            NumberInOrder = Int32.Parse(MyCookie.Value)
                        });

                        MyCookie.Expires = DateTime.Now.AddDays(-1);
                    }



                    db.SaveChanges();

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);


                    // For more information on how to enable account confirmation and password reset please visit https://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>");

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

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #14
0
 public FoodBookingsController(CateringContext context)
 {
     _context = context;
 }
Beispiel #15
0
        public ActionResult Plate()
        {
            TransactionViewModel transactionViewModel = new TransactionViewModel();

            int totalCost = 0;

            if (Request.IsAuthenticated)
            {
                var userId = User.Identity.GetUserId();

                Client client = new Client();

                foreach (var user in db.Clients)
                {
                    if (user.ClientId == userId)
                    {
                        client = user;
                        break;
                    }
                }

                var NumberedList = new List <NumberedViewModel>();

                transactionViewModel.ClientId = userId;
                transactionViewModel.Email    = client.Email;


                transactionViewModel.Address        = client.Address;
                transactionViewModel.ID_Card_Number = client.ID_Card_Number;
                transactionViewModel.ID_Card_Series = client.ID_Card_Series;

                foreach (var food in db.currentOrders)
                {
                    if (food.NumberInOrder > 0)
                    {
                        CateringContext temp    = new CateringContext();
                        Food            newFood = temp.foods.Find(food.FoodName);

                        NumberedList.Add(new NumberedViewModel()
                        {
                            Name   = food.FoodName,
                            Number = food.NumberInOrder,
                            Price  = newFood.Price
                        }
                                         );
                        totalCost += food.NumberInOrder * newFood.Price;
                    }
                }

                transactionViewModel.TotalCost = totalCost;
                transactionViewModel.Foods     = NumberedList;
            }
            else
            {
                CateringContext context      = new CateringContext();
                var             NumberedList = new List <NumberedViewModel>();

                foreach (var food in db.currentOrders)
                {
                    if (food.NumberInOrder > 0)
                    {
                        CateringContext temp    = new CateringContext();
                        Food            newFood = temp.foods.Find(food.FoodName);

                        NumberedList.Add(new NumberedViewModel()
                        {
                            Name   = food.FoodName,
                            Number = food.NumberInOrder,
                            Price  = newFood.Price
                        }
                                         );
                        totalCost += food.NumberInOrder * newFood.Price;
                    }
                }

                transactionViewModel.TotalCost = totalCost;
                transactionViewModel.Foods     = NumberedList;
            }
            return(View(transactionViewModel));
        }
Beispiel #16
0
 public FoodItemsController(CateringContext context)
 {
     _context = context;
 }
Beispiel #17
0
 public ChefRepository()
 {
     _ctx = new CateringContext();
 }
Beispiel #18
0
 public UnitOfWork(CateringContext context)
 {
     Context = context;
 }