public ActionResult Edit([Bind(Include = "CatId,CatName,Description,ParentCat")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); TempData["Success"] = "Wijzig"; return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "RelId,RelName,RelFirstName,RelAdress,RelPost,RelGemeente,RelPhone,RelEmail,RelationshipId")] Relation relation) { if (ModelState.IsValid) { db.Entry(relation).State = EntityState.Modified; db.SaveChanges(); TempData["Success"] = "De relatie werd succesvol gewijzigd"; return(RedirectToAction("Index")); } //ViewBag.RelationshipId = new SelectList(db.Relationships, "RelationshipId", "Description", relation.RelationshipId); return(View(relation)); }
public ActionResult Edit(UserRolesVM userRolesVM) { if (ModelState.IsValid) { User userToUpdate = db.Users.FirstOrDefault(u => u.UserId == userRolesVM.User.UserId); // map the properties we **actually** want to update: userToUpdate.UserName = userRolesVM.User.UserName; userToUpdate.UserPassword = userRolesVM.User.UserPassword; userToUpdate.UserEmail = userRolesVM.User.UserEmail; userToUpdate.Birthday = userRolesVM.User.Birthday; userToUpdate.UserLastName = userRolesVM.User.UserLastName; userToUpdate.UserFirstName = userRolesVM.User.UserFirstName; userToUpdate.UserAddress = userRolesVM.User.UserAddress; userToUpdate.UserPost = userRolesVM.User.UserPost; userToUpdate.UserGemeente = userRolesVM.User.UserGemeente; userToUpdate.UserName = userRolesVM.User.UserName; userToUpdate.UserPhone = userRolesVM.User.UserPhone; userToUpdate.PasswordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(userRolesVM.User.UserPassword, "md5"); var newRoles = db.Roles .Where(r => userRolesVM.SelectedUserRoles.Contains(r.RoleId)) .ToList(); var updatedRoles = new HashSet <int>(userRolesVM.SelectedUserRoles); foreach (Role role in db.Roles) { if (!updatedRoles.Contains(role.RoleId)) { userToUpdate.Roles.Remove(role); } else { userToUpdate.Roles.Add(role); } } db.Entry(userToUpdate).State = EntityState.Modified; db.SaveChanges(); TempData["Success"] = "De gebruiker werd succesvol gewijzigd"; return(RedirectToAction("Index")); } var errors = ModelState.Values.SelectMany(v => v.Errors); return(View(userRolesVM)); }
public ActionResult Edit([Bind(Include = "ProductId,ProductCode,ProductName,CatId,Description,Price,UrlImage,Spotlight")] Product product) { if (ModelState.IsValid) { // In het geval er geen afbeelding geselecteerd werd - omdat er bv. al een afbeelding stond // is product.UrlImage STEEDS NULL !!! Maw. de originele UrlImage wordt overschreven door NULL // Daarom gebruik ik een tijdelijke variabele 'image' waar ik de UrlImage UIT DE DATABASE haal // en koppel aan het betreffende product. var image = db.Products .AsNoTracking() .Where(x => x.ProductId == product.ProductId) .ToList(); if (image == null) { return(new HttpNotFoundResult()); } product.UrlImage = image[0].UrlImage; HttpPostedFileBase file = Request.Files["UploadImage"]; // Indien wel een afbeelding geselecteerd werd, wordt de nieuwe UrlImage ingelezen: if ((file != null) && (file.ContentLength > 0)) { product.UrlImage = Path.Combine("~/Data/images", file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/Data/images"), file.FileName)); } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); TempData["Success"] = "Het product werd succesvol gewijzigd"; return(RedirectToAction("Index")); } ViewBag.CatId = new SelectList(db.Categories, "CatId", "CatName", product.CatId); return(View(product)); }