Example #1
0
        public async Task <ActionResult> Register(RegisterViewModel model, string UserType)
        {
            PersonalnyContext db = new PersonalnyContext();

            /* var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
             * roleManager.Create(new IdentityRole("Trener"));
             * roleManager.Create(new IdentityRole("Podopieczny"));*/
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);



                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);


                    // Aby uzyskać więcej informacji o sposobie włączania potwierdzania konta i resetowaniu hasła, odwiedź stronę https://go.microsoft.com/fwlink/?LinkID=320771
                    // Wyślij wiadomość e-mail z tym łączem
                    // 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, "Potwierdź konto", "Potwierdź konto, klikając <a href=\"" + callbackUrl + "\">tutaj</a>");
                    if (UserType.Equals("Podopieczny"))
                    {
                        Podopieczny podopieczny = new Podopieczny {
                            UserName = model.Email, TrenerID = 1
                        };
                        UserManager.AddToRole(user.Id, "Podopieczny");

                        db.Podopiecznies.Add(podopieczny);
                        db.SaveChanges();

                        return(RedirectToAction("Edit", "Podopiecznies", new { id = podopieczny.ID }));
                    }
                    else if (UserType.Equals("Trener"))
                    {
                        UserManager.AddToRole(user.Id, "Trener");
                        Trener trener = new Trener {
                            UserName = model.Email
                        };                                                     //, Category = db.Categories.First()

                        db.Treners.Add(trener);
                        db.SaveChanges();

                        return(RedirectToAction("Edit", "Treners", new { id = trener.ID }));
                    }

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

            // Dotarcie do tego miejsca wskazuje, że wystąpił błąd, wyświetl ponownie formularz
            return(View(model));
        }
 public ActionResult Odblok([Bind(Include = "Id,TrenerID,PodopiecznyID,RodzajPlanuID,Cena,Plik,Zablokowany")] Plan plan)
 {
     if (ModelState.IsValid)
     {
         db.Entry(plan).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(plan));
 }
        public ActionResult Create([Bind(Include = "Id,NazwaCwiczenia,IloscSerii,ZakresPowtorzen,CzasPrzerwy,SkalaRpes,TempoPracy")] Cwiczenie cwiczenie)
        {
            if (ModelState.IsValid)
            {
                db.Cwiczenies.Add(cwiczenie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cwiczenie));
        }
        public ActionResult Create([Bind(Include = "ID,UserName")] Podopieczny podopieczny)
        {
            if (ModelState.IsValid)
            {
                db.Podopiecznies.Add(podopieczny);
                db.SaveChanges();
                return(RedirectToAction("Home", "Index"));
            }

            return(View(podopieczny));
        }
        public ActionResult Create([Bind(Include = "ID,Avatar,UserName,Imie,Nazwisko,Wiek,LiczbaMaksPodopiecznych,Numerkonta")] Trener trener)
        {
            if (ModelState.IsValid)
            {
                db.Treners.Add(trener);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(trener));
        }
Example #6
0
        public ActionResult Create([Bind(Include = "Id,UserName,Tresc,datautworzenia")] Notka notka)
        {
            if (ModelState.IsValid)
            {
                db.Notkas.Add(notka);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(notka));
        }
Example #7
0
        public ActionResult Create([Bind(Include = "Id,TrenerId,PodopiecznyId,Tresc")] Wiadomosc wiadomosc)
        {
            if (ModelState.IsValid)
            {
                wiadomosc.Autor = User.Identity.Name;
                db.Wiadomoscs.Add(wiadomosc);
                db.SaveChanges();
                return(RedirectToAction("Index", "Wiadomoscs", new { UserName = User.Identity.Name }));
            }

            return(RedirectToRoute("Index", "Treners"));
        }
        public ActionResult Create([Bind(Include = "Id,TrenerID,PodopiecznyID,RodzajPlanuID,CwiczenieID,Cwiczenie1ID,Cwiczenie2ID,Cwiczenie3ID,Cwiczenie4ID,Cwiczenie5ID,Zablokowany,Cena")] PlanKreator planKreator)
        {
            if (ModelState.IsValid)
            {
                Trener tr = db.Treners.Single(t => t.UserName == User.Identity.Name);
                planKreator.TrenerID = (int)tr.ID;
                db.PlanKreators.Add(planKreator);

                db.SaveChanges();
                return(RedirectToAction("Index", "PlanKreators", new { UserName = User.Identity.Name }));
            }

            return(View(planKreator));
        }