public void UpdateItem(string id) { if (!master.isAdmin) { master.ShowErrorMessage("Not authorized."); return; } EventDay item = null; item = dbContext.EventDays.Find(int.Parse(id)); if (item == null) { ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(item); if (ModelState.IsValid) { dbContext.Entry(item).State = EntityState.Modified; dbContext.SaveChanges(); master.ShowSuccessMessage("Item updated"); this.DataBind(); } }
public void UpdateItem(string id) { if (!master.isAdmin && id != User.Identity.GetUserId()) { master.ShowErrorMessage("Not authorized."); return; } //var user = data.Users.Find(id); User user = null; user = data.Users.Find(id); if (user == null) { ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(user); if (ModelState.IsValid) { var fileUploadControl = (FileUpload)FormViewUserDetails.FindControl("FileUploadControl"); if (fileUploadControl.HasFile) { string fileName = user.UserName + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".jpg"; fileUploadControl.SaveAs(Server.MapPath("~/Uploaded_Files/") + fileName); user.Avatar = fileName; } user.Events.Clear(); var lbEvents = (ListBox)FormViewUserDetails.FindControl("ListBoxEditEvents"); foreach (ListItem ev in lbEvents.Items) { var evId = int.Parse(ev.Value); var eventToAdd = data.Events.FirstOrDefault(x => x.Id == evId); user.Events.Add(eventToAdd); } data.Entry(user).State = EntityState.Modified; data.SaveChanges(); master.ShowSuccessMessage("Item updated"); this.DataBind(); } }
public void GridViewRoutes_UpdateItem(int id) { Route item = null; item = data.Routes.Find(id); if (item == null) { ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(item); if (ModelState.IsValid) { data.Entry(item).State = EntityState.Modified; data.SaveChanges(); master.ShowSuccessMessage("Item updated"); this.DataBind(); } }
public void UpdateItem(string id) { if (!master.isAdmin && id != User.Identity.GetUserId()) { master.ShowErrorMessage("Not authorized."); return; } var user = data.Users.Find(id); User item = null; item = data.Users.Find(id); if (item == null) { ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(item); if (ModelState.IsValid) { var fileUploadControl = (FileUpload)FormViewUserDetails.FindControl("FileUploadControl"); if (fileUploadControl.HasFile) { string fileName = user.UserName + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".jpg"; fileUploadControl.SaveAs(Server.MapPath("~/Uploaded_Files/") + fileName); user.Avatar = fileName; } data.Entry(item).State = EntityState.Modified; data.SaveChanges(); master.ShowSuccessMessage("Item updated"); this.DataBind(); } }