Esempio n. 1
0
        public ActionResult Create([Bind(Include = "PetOwnerID,AverageRating,GeneralNeeds,HomeAccess,UserID")] DAL.PetOwner petOwner)
        {
            if (ModelState.IsValid)
            {
                //Changing Current user to a Pet Owner
                var identityID = User.Identity.GetUserId();

                DAL.PetopiaUser currentUser = pdb.PetopiaUsers.Where(x => x.ASPNetIdentityID == identityID).First();

                currentUser.IsOwner          = true;
                pdb.Entry(currentUser).State = EntityState.Modified;


                //Roles.AddUserToRole(currentUser.ASPNetIdentityID, "Owner");
                var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

                var theUser = UserManagerExtensions.FindByName(userManager, currentUser.ASPNetIdentityID);

                UserManagerExtensions.AddToRole(userManager, identityID, "Owner");
                //needs details, access instructions

                pdb.SaveChanges();

                petOwner.UserID = pdb.PetopiaUsers.Where(x => x.ASPNetIdentityID == identityID)
                                  .Select(x => x.UserID).First();

                pdb.PetOwners.Add(petOwner);

                pdb.SaveChanges();

                return(RedirectToAction("Index", "ProfilePage"));
            }

            return(View(petOwner));
        }
Esempio n. 2
0
        public ActionResult Edit([Bind(Include = "PetOwnerID,AverageRating,GeneralNeeds,HomeAccess,UserID")] DAL.PetOwner petOwner)
        {
            if (ModelState.IsValid)
            {
                db.Entry(petOwner).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(petOwner));
        }