public void DropDownList() { using (var kontekst = new Kontekst()) { var possibleFoods = kontekst.Foods .ToList(); var selectItems = new List <System.Web.Mvc.SelectListItem>(); var listItem = new SelectListItem(); listItem.Text = "- choose -"; listItem.Value = ""; selectItems.Add(listItem); foreach (var food in possibleFoods) { listItem = new SelectListItem(); listItem.Text = food.Name; listItem.Value = food.Id.ToString(); listItem.Selected = false; selectItems.Add(listItem); } ViewBag.PossibleFoods = selectItems; } }
public ActionResult AddFoodToMeal(ViewModelForMeal viewModel)//int selected, int id) { this.DropDownList(); var kontekst = new Kontekst(); Food result = kontekst.Foods .FirstOrDefault(p => p.Id == viewModel.SelectedId); Recipe resultRecipe = new Recipe(); resultRecipe = kontekst.Recipes .Where(p => p.Id == viewModel.MealId) .FirstOrDefault(); resultRecipe.TotalCalories += result.Calories * resultRecipe.NoServings; resultRecipe.TotalCarbos += Convert.ToInt32(result.Carbs * resultRecipe.NoServings); resultRecipe.TotalFats += Convert.ToInt32(result.Fat * resultRecipe.NoServings); resultRecipe.TotalProteins += Convert.ToInt32(result.Protein * resultRecipe.NoServings); resultRecipe.Foods.Add(result); kontekst.SaveChanges(); kontekst.Dispose(); return(View("Details", resultRecipe)); }
public ActionResult Index() { Zamówienie[] zamówienia; bool admin = Session["admin"] != null; using (Kontekst kontekst = new Kontekst()) { IQueryable <Zamówienie> zamówieniaPośrednie = kontekst.Zamówienia; if (!admin) { HttpCookie ciastko = Request.Cookies["idSklepu"]; if (ciastko == null) { return(RedirectToAction("Index", "Sklepy")); } long idSklepu = Convert.ToInt64(ciastko.Value); zamówieniaPośrednie = zamówieniaPośrednie.Where(z => z.SklepId == idSklepu); } zamówienia = zamówieniaPośrednie.Include(z => z.Kolor).Include(z => z.Status).Include(z => z.Zasób).Include(z => z.Zasób.Kolory).OrderBy(z => z.StatusId).ThenByDescending(z => z.DataZłożenia).ToArray(); } return(View(zamówienia)); }
private static void UzupełnijModelDodawania(Dodaj model) { using (Kontekst kontekst = new Kontekst()) { model.Sklepy = kontekst.Sklepy.ToArray(); model.Zasoby = kontekst.Zasoby.Include(z => z.Kolory).ToArray(); } }
public static Jezik IzDatoteka(string kod) { string infoPut = "./jezici/" + kod + "/"; StreamReader citacPopisa = new StreamReader(infoPut + "info.txt"); string nazivJezika = citacPopisa.ReadLine(); List <string> datoteke = new List <string>(); while (!citacPopisa.EndOfStream) { string linija = citacPopisa.ReadLine().Trim(); if (linija.Length > 0) { datoteke.Add(linija); } } citacPopisa.Close(); Dictionary <Kontekst, Queue <string> > redovi = new Dictionary <Kontekst, Queue <string> >(); foreach (string datoteka in datoteke) { Kontekst kontekst = Kontekst.Opcenito; StreamReader citac = new StreamReader(infoPut + datoteka); while (!citac.EndOfStream) { string linija = citac.ReadLine(); if (linija.StartsWith("::")) { kontekst = StringUKontekst[linija.Substring(2)]; if (!redovi.ContainsKey(kontekst)) { redovi.Add(kontekst, new Queue <string>()); } } else { redovi[kontekst].Enqueue(linija); } } citac.Close(); } Dictionary <Kontekst, Dictionary <string, ITekst> > tablica = new Dictionary <Kontekst, Dictionary <string, ITekst> >(); foreach (Kontekst kontekst in redovi.Keys) { tablica.Add(kontekst, new Dictionary <string, ITekst>()); foreach (KeyValuePair <string, ITekst> redak in Tekst.IzStringa(redovi[kontekst])) { tablica[kontekst].Add(redak.Key, redak.Value); } } return(new Jezik(nazivJezika, kod, tablica)); }
public ActionResult Index() { Index model = new Index(); using (Kontekst kontekst = new Kontekst()) model.Sklepy = kontekst.Sklepy.ToArray(); return(View(model)); }
public new int Interpretuj(Kontekst kontekst) { if (a.Interpretuj(kontekst) < b.Interpretuj(kontekst)) { return(1); } else { return(0); } }
public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Manage")); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return(View("ExternalLoginFailure")); } model.CaloriesPerDay = OptimalCaloriesCounter2(model); var user = new User { UserName = model.Email, Email = model.Email, Name = model.Name, LastName = model.LastName, Age = model.Age, CurrentWeight = model.CurrentWeight, GoalWeight = model.GoalWeight, Height = model.Height, LevelOfActivity = model.SelectedLevel, Gender = model.Gender, DailyCalories = model.CaloriesPerDay }; var progress = new Progress(); progress.UserId = user.Id; progress.UserDailyCalories = user.DailyCalories; progress.Weight = user.CurrentWeight; Kontekst kontekst = new Kontekst(); kontekst.Progress.Add(progress); kontekst.SaveChanges(); kontekst.Dispose(); var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(View("UserHome", user)); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public ActionResult Status(long id) { Status model = new Status(); using (Kontekst kontekst = new Kontekst()) model.Zamówienie = kontekst.Zamówienia.Include(z => z.Kolor).Include(z => z.Zasób).Single(z => z.Id == id); UzupełnijModelStatusu(model); return(View(model)); }
public new int Interpretuj(Kontekst kontekst) { if (porównanie.Interpretuj(kontekst) != 0) { return(prawda.Interpretuj(kontekst)); } else { return(fałsz.Interpretuj(kontekst)); } }
public ActionResult Status(Status model) { using (Kontekst kontekst = new Kontekst()) { Zamówienie noweZamówienie = model.Zamówienie; Zamówienie dotychczasoweZamówienie = kontekst.Zamówienia.Find(noweZamówienie.Id); dotychczasoweZamówienie.StatusId = noweZamówienie.StatusId; kontekst.Entry(dotychczasoweZamówienie).State = EntityState.Modified; kontekst.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Usuń(long id) { using (Kontekst kontekst = new Kontekst()) { DbSet <Zamówienie> zamówienia = kontekst.Zamówienia; Zamówienie zamówienie = zamówienia.Find(id); if (zamówienie != null) { zamówienia.Remove(zamówienie); kontekst.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult PotwierdźOdbiór(long id) { using (Kontekst kontekst = new Kontekst()) { Zamówienie zamówienie = kontekst.Zamówienia.Find(id); if (zamówienie != null) { zamówienie.StatusId = 3; kontekst.Entry(zamówienie).State = EntityState.Modified; kontekst.SaveChanges(); } } return(Index()); }
public ActionResult Index(Administrator model) { Administrator administrator; using (Kontekst kontekst = new Kontekst()) administrator = kontekst.Administratorzy.SingleOrDefault(a => (a.Nazwa == model.Nazwa) && (a.Hasło == model.Hasło)); if (administrator == null) { ModelState.AddModelError("Błąd logowania", "Nazwa użytkownika i/lub hasło są nieprawidłowe."); return(View(model)); } Session["admin"] = administrator; return(RedirectToAction("Index", "Zamówienia")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { model.CaloriesPerDay = OptimalCaloriesCounter(model); var user = new User { UserName = model.Email, Email = model.Email, Name = model.Name, LastName = model.LastName, Age = model.Age, CurrentWeight = model.CurrentWeight, GoalWeight = model.GoalWeight, Height = model.Height, LevelOfActivity = model.SelectedLevel, Gender = model.Gender, DailyCalories = model.CaloriesPerDay }; Progress progress = new Progress(); progress.UserId = user.Id; progress.UserDailyCalories = user.DailyCalories; progress.Weight = user.CurrentWeight; Kontekst kontekst = new Kontekst(); kontekst.Progress.Add(progress); kontekst.SaveChanges(); kontekst.Dispose(); 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 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(View("UserHome", user)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
static void Main() { Console.WriteLine("'if x<7 then y else 3', gdzie x=5, y=2:"); Kontekst kontekst = new Kontekst(); kontekst.zmienne["x"] = 5; kontekst.zmienne["y"] = 2; var wyrażenie = new WyrażenieWarunkowe( new WyrażenieMniejszeNiż( new Zmienna("x"), new Stała(7) ), new Zmienna("y"), new Stała(3) ); int wynik = wyrażenie.Interpretuj(kontekst); Console.WriteLine(wynik); }
public ActionResult Dodaj(Dodaj model) { if (ModelState.IsValid) { Zamówienie zamówienie = model.Zamówienie; zamówienie.DataZłożenia = DateTime.Now; using (Kontekst kontekst = new Kontekst()) { kontekst.Zamówienia.Add(zamówienie); kontekst.SaveChanges(); } return(RedirectToAction("Index")); } UzupełnijModelDodawania(model); return(View(model)); }
public ActionResult AddFoodToMeal(ViewModelForMeal viewModel)//int selected, int id) { this.DropDownList(); var kontekst = new Kontekst(); Food result = kontekst.Foods .FirstOrDefault(p => p.Id == viewModel.SelectedId); viewModel.Foods.Add(result); Meal resultMeal = new Meal(); resultMeal = kontekst.Meals .Where(p => p.Id == viewModel.MealId) .FirstOrDefault(); resultMeal.Foods.Add(result); kontekst.SaveChanges(); kontekst.Dispose(); return(View("Details", resultMeal)); }
public int Interpretuj(Kontekst kontekst) { return(kontekst.zmienne[this.symbol]); }
public frmBiblioteczka() { InitializeComponent(); this.kontekst = new Kontekst(); lbKsiazki.DataSource = kontekst.KolekcjaKsiazek; }
/// <summary> /// @param kontekst /// @return /// </summary> public int Interpretuj(Kontekst kontekst) { // TODO implement here return(0); }
public int Interpretuj(Kontekst kontekst) { return(this.wartość); }
public Dictionary <string, ITekst> this[Kontekst kontekst] { get { return(tablica[kontekst]); } }
public ITekst this[Kontekst kontekst, string kljuc] { get { return(tablica[kontekst][kljuc]); } }
private static void UzupełnijModelStatusu(Status model) { using (Kontekst kontekst = new Kontekst()) model.Statusy = kontekst.StatusyZamówień.ToArray(); }