Ejemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };                                                                             //------------------------------------------------------------------ <= TUTAJ

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

                if (result.Succeeded)
                {
                    ApplicationUser user2 = UserManager.FindByName(model.Email);
                    UserManager.AddToRole(user2.Id, "user");

                    UzytkownicyModels uz = new UzytkownicyModels();
                    uz.Nazwa = model.Email;

                    db.Uzytkownik.Add(uz);
                    db.SaveChanges();
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

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

            // Dotarcie do tego miejsca wskazuje, że wystąpił błąd, wyświetl ponownie formularz
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Delete(int id)
        {
            UzytkownicyModels ownerModel = db.Uzytkownik.Find(id);

            db.Uzytkownik.Remove(ownerModel);
            db.SaveChanges();                       //zapis zmian
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "ID,Nazwa,Data_dolaczenia")] UzytkownicyModels ownerModelUpdated)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ownerModelUpdated).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ownerModelUpdated));
 }
Ejemplo n.º 4
0
 public ActionResult Create([Bind(Include = "Nazwa,Data_dolaczenia")] UzytkownicyModels ownerModel)
 {
     if (ModelState.IsValid)
     {
         db.Uzytkownik.Add(ownerModel);
         db.SaveChanges();                       //zapis zmian
         return(RedirectToAction("Index"));
     }
     return(View(ownerModel));       //zostaną dane w formularzu
 }
Ejemplo n.º 5
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            UzytkownicyModels ownerModel = db.Uzytkownik.Find(id);

            if (ownerModel == null)
            {
                return(HttpNotFound());
            }
            return(View(ownerModel));
        }