示例#1
0
        public ActionResult Login(FormCollection collection)
        {
            if (Session["UserId"] == null)
            {
                FoodOrderContext db = new FoodOrderContext();

                string username = collection["UserName"];
                string password = collection["Password"];

                Registration p = null;
                try
                {
                    p = db.Registrations.Single(u => u.UserName == username && u.Password == password);
                }
                catch (Exception ex) { }

                if (p != null)
                {
                    Session["UserId"]   = p.CustomerID.ToString();
                    Session["Username"] = p.CustomerName.ToString();
                    return(View("Profile"));
                }
                else
                {
                    ModelState.AddModelError("", "Incorrect username or password");
                    return(View());
                }
            }
            else
            {
                return(View("Profile"));
            }
        }
示例#2
0
        public async Task AddDishItem()
        {
            var context = new FoodOrderContext().CreateDbContext(null);
            var repo    = new FoodOrderRepository(context);
            var date    = DateTime.Now;

            var dishItem = new DishItem
            {
                Name     = "Salo",
                Price    = 100,
                Category = new DishCategory
                {
                    Name = "Еда богов"
                },
                Supplier    = repo.All <Supplier>().FirstOrDefault(x => x.Name == "ГлаголЪ"),
                AvailableOn = new List <DishItemToWeekDay> {
                    new DishItemToWeekDay {
                        WeekDay = repo.GetById <WeekDay>(1)
                    }
                },
                AvailableUntil = date
            };

            await repo.InsertAsync(dishItem);

            await repo.SaveAsync();

            var i = repo.All <DishItem>().Include(x => x.AvailableOn).FirstOrDefault(x => x.AvailableUntil == date);

            Assert.Equal(dishItem.AvailableOn.First().DishItemId, i.AvailableOn.First().DishItemId);
            Assert.Equal(dishItem.AvailableOn.First().WeekDayId, i.AvailableOn.First().WeekDayId);
        }
示例#3
0
 public async Task TestSync()
 {
     var context = new FoodOrderContext().CreateDbContext(null);
     var repo    = new FoodOrderRepository(context);
     var service = new FoodService(repo, new GoogleSpreadsheetProvider());
     await service.SynchronizeFood();
 }
示例#4
0
 public UnitOfWork(FoodOrderContext context)
 {
     _context    = context;
     Ingredients = new FoodOrderRepository <IngredientModel>(context);
     Pizzas      = new FoodOrderRepository <PizzaModel>(context);
     Starters    = new FoodOrderRepository <StarterModel>(context);
     Users       = new FoodOrderRepository <UserModel>(context);
     Photos      = new FoodOrderRepository <PhotoModel>(context);
     Orders      = new FoodOrderRepository <OrderModel>(context);
 }
示例#5
0
        public ActionResult CustomerAccountInfo()
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("Login"));
            }
            else
            {
                FoodOrderContext hc = new FoodOrderContext();
                Registration     p  = hc.Registrations.Find(Int32.Parse(Session["UserId"].ToString()));

                return(View(p));
            }
        }
示例#6
0
        public ActionResult Register(FormCollection collection)
        {
            bool filledUp = true;

            foreach (string key in collection.AllKeys)
            {
                if (key.StartsWith("_"))
                {
                    continue;
                }

                /*
                 * Response.Write("Key = " + key + " , ");
                 * Response.Write("Value = " + collection[key]);
                 * Response.Write("<br/>");
                 */
                if (collection[key] == "")
                {
                    filledUp = false;
                }
            }

            if (filledUp)
            {
                Registration p = new Registration
                {
                    CustomerName    = collection["CustomerName"],
                    Phonenumber     = collection["Phonenumber"],
                    Email           = collection["Email"],
                    DeliveryAddress = collection["DeliveryAddress"],
                    UserName        = collection["UserName"],
                    Password        = collection["Password"]
                };

                FoodOrderContext foodOrderContext = new FoodOrderContext();
                foodOrderContext.Registrations.Add(p);
                foodOrderContext.SaveChanges();

                Session["UserId"]   = p.CustomerID.ToString();
                Session["UserName"] = p.CustomerName.ToString();
                return(View("Profile"));
            }

            return(View());
        }
示例#7
0
        public void TestDb()
        {
            var context = new FoodOrderContext().CreateDbContext(null);

            context.WeekDays.Add(new WeekDay {
                Name = "Wd"
            });
            context.SaveChanges();
            var t = context.WeekDays.FirstOrDefault(x => x.Name == "Wd");

            Assert.Equal(t.Name, "Wd");

            context.Remove(t);
            context.SaveChanges();
            var w = context.WeekDays.FirstOrDefault(x => x.Name == "Wd");

            Assert.Null(w);
        }
示例#8
0
        public void FillDatabaseWithUsers()
        {
            var context = new FoodOrderContext().CreateDbContext(null);
            var repo    = new FoodOrderRepository(context);

            var prevCount = repo.All <User>().Count();

            repo.InsertAsync(
                new User[]
            {
                new User
                {
                    Email     = "*****@*****.**",
                    FirstName = "FakeFirst",
                    LastName  = "FakeLast"
                },
                new User
                {
                    Email     = "*****@*****.**",
                    FirstName = "Admin",
                    LastName  = "Admin"
                },
                new User
                {
                    Email     = "*****@*****.**",
                    FirstName = "Egor",
                    LastName  = "Manevich"
                },
                new User
                {
                    Email     = "*****@*****.**",
                    FirstName = "Human",
                    LastName  = "Human"
                },
            });
            repo.Save();
            var currentCount = repo.All <User>().Count();
            var diff         = currentCount - prevCount;

            Assert.Equal(diff, 4);
        }
 public CategoriesController(FoodOrderContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
示例#10
0
 public UnitOfWork(FoodOrderContext context)
 {
     _context = context;
 }
示例#11
0
 public OrdersController(FoodOrderContext context)
 {
     _context = context;
 }
示例#12
0
 public FoodRepository(FoodOrderContext context)
 {
     _context = context;
 }
示例#13
0
 public FoodOrderRepository(FoodOrderContext context)
 {
     _dbSet = context.Set <TEntity>();
 }