Esempio n. 1
0
 public ActionResult Create(string roleId, string userId)
 {
     if (ModelState.IsValid)
     {
         var user = db.AspNetUsers.Find(userId);
         var role = db.AspNetRoles.Find(roleId);
         role.AspNetUsers.Add(user);
         db.Entry(role).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "AspNetRole"));
     }
     return(RedirectToAction("Create"));
 }
Esempio n. 2
0
 public ActionResult Edit([Bind(Include = "Id,Name")] AspNetRole aspNetRole)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetRole).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(aspNetRole));
 }
Esempio n. 3
0
        public ActionResult Edit(Product model, HttpPostedFileBase picture)
        {
            ValidateProduct(model);
            if (ModelState.IsValid)
            {
                using (var scope = new TransactionScope())
                {
                    db.Entry(model).State = EntityState.Modified;
                    db.SaveChanges();

                    if (picture != null)
                    {
                        var path = Server.MapPath(Picture_PATH);
                        picture.SaveAs(path + model.id);
                    }
                    scope.Complete();
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.cate_id = new SelectList(db.Categories, "id", "name", model.cate_id);
            return(View(model));
        }