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")); } }
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); }
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(); }
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); }
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)); } }
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()); }
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); }
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; }
public UnitOfWork(FoodOrderContext context) { _context = context; }
public OrdersController(FoodOrderContext context) { _context = context; }
public FoodRepository(FoodOrderContext context) { _context = context; }
public FoodOrderRepository(FoodOrderContext context) { _dbSet = context.Set <TEntity>(); }