public ActionResult Edit(EditVM vm, int id) { TodoItemBL todoItemBL = new TodoItemBL(); todoItemBL.UpdateItem(vm, id); return(RedirectToAction("List")); }
public ActionResult Edit(EditVM model) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } if (!HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser").IsAdmin) { return(RedirectToAction("Login", "Home")); } if (!ModelState.IsValid) { return(View(model)); } User item = new User { Id = model.Id, Username = model.Username, Email = model.Email, IsAdmin = model.IsAdmin }; using RestaurantManagerContext context = new RestaurantManagerContext(); context.Users.Update(item); context.SaveChanges(); return(RedirectToAction("Index", "User")); }
public ActionResult Edit(EditVM model) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } if (!HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser").IsAdmin) { return(RedirectToAction("Login", "Home")); } if (!ModelState.IsValid) { return(View(model)); } User item = new User { Id = model.Id, Username = model.Username, Password = model.Password, FirstName = model.FirstName, LastName = model.LastName }; using ToDoManagerContext context = new ToDoManagerContext(); context.Users.Update(item); context.SaveChanges(); return(RedirectToAction("Index", "User")); }
public ActionResult Edit(EditVM model) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } if (!ModelState.IsValid) { return(View(model)); } Project item = new Project { Id = model.Id, LeadId = model.LeadId, Title = model.Title, Description = model.Description }; using ToDoManagerContext context = new ToDoManagerContext(); context.Projects.Update(item); context.SaveChanges(); return(RedirectToAction("Index", "Project")); }
public async Task <IActionResult> Edit(EditVM userViewModel) { if (!ModelState.IsValid) { return(View(userViewModel)); } var user = await _userManager.FindByIdAsync(userViewModel.Id); if (user == null) { return(NotFound()); } user.FullName = userViewModel.FullName; user.Email = userViewModel.Email; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction("Index")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(View(userViewModel)); }
public ActionResult Edit(EditVM model) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } if (!ModelState.IsValid) { return(View(model)); } WorkLog item = new WorkLog { Id = model.Id, TaskId = model.TaskId, UserId = model.UserId, Hours = model.Hours, CreateDate = model.Date }; using ToDoManagerContext context = new ToDoManagerContext(); context.WorkLogs.Update(item); context.SaveChanges(); return(RedirectToAction("Index", "WorkLog", new { taskId = model.TaskId })); }
public async Task <IActionResult> Edit(int id, EditVM model) { if (id != model.Id) { return(NotFound()); } if (!ModelState.IsValid) { return(View(model)); } Branch branch = await _dbContext.Branches.FirstOrDefaultAsync(b => b.Id == id); if (branch == null) { return(NotFound()); } // Binds the view model: branch.Name = model.Name; branch.Address = model.Address; branch.PhoneNumber = model.PhoneNumber; branch.OpeningHours = model.OpeningHours; branch.LocationLatitude = model.LocationLatitude; branch.LocationLongitude = model.LocationLongitude; branch.DateLastModified = DateTime.Now; _dbContext.Branches.Update(branch); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(int?id) { ProductsRepository productsRepo = new ProductsRepository(); GenresRepository genresRepo = new GenresRepository(); Product item = id == null ? new Product() : productsRepo.GetById(id.Value); EditVM model = new EditVM(); model.Id = item.Id; model.GenreId = item.GenreId; model.Artist = item.Artist; model.Title = item.Title; model.Genres = new SelectList ( genresRepo.GetAll(), "Id", "Name", model.GenreId ); model.Price = item.Price; model.VinylImgPath = item.VinylImgPath; model.OnSale = item.OnSale; return(View(model)); }
public IActionResult Edit(EditVM model) { if (!ModelState.IsValid) { return(View(model)); } User item = new User(); item.Id = model.Id; item.Username = model.Username; item.Password = model.Password; item.FirstName = model.FirstName; item.LastName = model.LastName; if (item.Id <= 0) { _context.Users.Add(item); } else { _context.Entry(item).State = EntityState.Modified; } _context.SaveChanges(); return(RedirectToAction("Index", "Users")); }
public ActionResult Edit(int id, FormCollection collection) { EditVM model = new EditVM(); TryUpdateModel(model); if (!ModelState.IsValid) { return(View(model)); } User user; if (model.ID != 0) { user = usersService.GetByID(model.ID); } else { user = new User(); } if (user == null) { return(RedirectToAction("List")); } user.Username = model.Username; user.Password = model.Password; user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; user.IsAdmin = model.IsAdmin; user.ID = model.ID; usersService.Save(user); return(RedirectToAction("List")); }
public async Task <IActionResult> Edit(int id, EditVM model) { if (id != model.Id) { return(NotFound()); } if (!ModelState.IsValid) { return(View(model)); } DeliveryMethod deliveryMethod = await _dbContext.DeliveryMethods.FirstOrDefaultAsync(d => d.Id == id); if (deliveryMethod == null) { return(NotFound()); } // Binds the view model: deliveryMethod.Name = model.Name; deliveryMethod.Description = model.Description; deliveryMethod.Price = model.Price; deliveryMethod.DateLastModified = DateTime.Now; _dbContext.DeliveryMethods.Update(deliveryMethod); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(int?id) { EditVM model = new EditVM(); User user; if (id.HasValue) { user = usersService.GetByID(id.Value); if (user == null) { return(RedirectToAction("List")); } } else { user = new User(); } model.Username = user.Username; model.Password = user.Password; model.FirstName = user.FirstName; model.LastName = user.LastName; model.Email = user.Email; model.IsAdmin = user.IsAdmin; model.ID = user.ID; return(View(model)); }
public ActionResult Edit(EditVM vm) { IModelResult reposResult; if (ModelState.IsValid) { reposResult = repository.UpdateStudent(vm); if (reposResult.IsOk) { return(RedirectToAction("Index")); } else { //錯誤頁 TempData["error"] = reposResult; return(RedirectToAction("Message", "Error")); } } else { string msg = string.Join("/n", ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => string.Join("/n", x.Value.Errors.Select(y => y.ErrorMessage).ToList()))); reposResult = new ModelResult(SystemCodes.Codes.ModelValidError) { SystemMessage = msg }; TempData["error"] = reposResult; return(RedirectToAction("Message", "Error")); } }
//public async Task<ActionResult> Edit([Bind(Include = "Id,Brand,Description,Qty,Cost,Price,Country,Provider,Warranty,DateAd,DateCr,DateUp")] Products products) //{ // if (ModelState.IsValid) // { // db.Entry(products).State = EntityState.Modified; // await db.SaveChangesAsync(); // return RedirectToAction("Index"); // } // return View(products); //} public async Task <ActionResult> Edit(EditVM model, int?id) { if (ModelState.IsValid) { Products exProd = await db.Products.FindAsync(id); if (exProd != null) { exProd.Item = model.Item; exProd.Brand = model.Brand; exProd.Description = model.Description; exProd.Qty = model.Qty; exProd.Cost = model.Cost; exProd.Price = model.Price; exProd.Country = model.Country; exProd.Provider = model.Provider; exProd.Warranty = model.Warranty; exProd.DateAd = model.DateAd; exProd.DateUp = DateTimeOffset.Now; } else { return(HttpNotFound()); } db.Entry(exProd).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Edit(EditVM model) { if (!ModelState.IsValid) { return(View(model)); } Movie item = new Movie(); item.Id = model.Id; item.Name = model.Name; item.Producer = model.Producer; item.Rating = model.Rating; if (item.Id <= 0) { _context.Movies.Add(item); } else { _context.Entry(item).State = EntityState.Modified; } _context.SaveChanges(); return(RedirectToAction("Index", "Movies")); }
public async Task <ActionResult> Edit([Bind(Include = "userToEdit")] EditVM editVM, int UserTypeId) { editVM.userToEdit.UserTypeId = UserTypeId; var model = new EditVM(); if (ModelState.IsValid) { db.Entry(editVM.userToEdit).State = EntityState.Modified; await db.SaveChangesAsync(); if (editVM.userToEdit.UserId == model.CurrentUserInstance.UserId) { model.CurrentUserInstance = editVM.userToEdit; model.editedUser = editVM.userToEdit; return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Employ", "Users")); } } ViewBag.UserTypeId = new SelectList(db.UserTypes, "UserTypeId", "UserTypeText", editVM.userToEdit.UserTypeId); return(View(model)); }
public ActionResult Edit(EditVM model) { if (!ModelState.IsValid) { return(View(model)); } UsersRepository repo = new UsersRepository(); User item = new User(); item.Id = model.Id; item.Username = model.Username; item.Password = model.Password; item.FirstName = model.FirstName; item.LastName = model.LastName; if (item.Id > 0) { repo.Update(item); } else { repo.Insert(item); } return(RedirectToAction("AdminPanel", "Account")); }
public ActionResult Edit(EditVM model) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } if (!ModelState.IsValid) { return(View(model)); } Task item = new Task { Id = model.Id, ProjectId = model.ProjectId, Title = model.Title, Description = model.Description, AssigneeId = model.AssigneeId }; using ToDoManagerContext context = new ToDoManagerContext(); context.Tasks.Update(item); context.SaveChanges(); return(RedirectToAction("Index", "Task", new { projectId = model.ProjectId })); }
public ActionResult Edit(EditVM model) { Employee loggedEmployee = (Employee)Session["loggedEmployee"]; if (!ModelState.IsValid) { return(View(model)); } CustomersRepository repo = new CustomersRepository(); Customer item = new Customer(); item.Id = model.Id; item.EmployeeId = loggedEmployee.Id; item.FirstName = model.FirstName; item.LastName = model.LastName; item.EGN = model.EGN; item.Phone = model.Phone; item.Address = model.Address; if (item.Id > 0) { repo.Update(item); } else { repo.Insert(item); } return(RedirectToAction("Index", "Customers")); }
// GET: Task/Edit/5 public ActionResult Edit(int id) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } using ToDoManagerContext context = new ToDoManagerContext(); Task item = context.Tasks.Find(id); EditVM model = new EditVM { Id = item.Id, ProjectId = item.ProjectId, Title = item.Title, Description = item.Description, UserPairs = context.Users.Select(u => new SelectListItem { Text = u.Username, Value = u.Id.ToString(), Selected = item.AssigneeId == u.Id }).ToList() }; return(View(model)); }
public ActionResult Edit(EditVM model) { if (!ModelState.IsValid) { return(View(model)); } EmployeesRepository repo = new EmployeesRepository(); Employee item = new Employee(); item.Id = model.Id; item.Username = model.Username; item.Password = model.Password; item.FirstName = model.FirstName; item.LastName = model.LastName; item.Phone = model.Phone; item.Email = model.Email; if (item.Id > 0) { repo.Update(item); } else { repo.Insert(item); } return(RedirectToAction("Index", "Employees")); }
public async Task <IActionResult> Edit(int id, EditVM model) { if (id != model.Id) { return(NotFound()); } if (!ModelState.IsValid) { return(View(model)); } Sale sale = await _dbContext.Sales.FirstOrDefaultAsync(s => s.Id == id); if (sale == null) { return(NotFound()); } // Binds the view model: sale.Name = model.Name; sale.DiscountRate = model.DiscountRate; sale.DateStart = model.DateStart; sale.DateEnd = model.DateEnd; sale.DateLastModified = DateTime.Now; _dbContext.Sales.Update(sale); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, EditVM model) { if (id != model.Id) { return(NotFound()); } if (!ModelState.IsValid) { return(View(model)); } ProductType type = await _dbContext.ProductTypes.FirstOrDefaultAsync(c => c.Id == id); if (type == null) { return(NotFound()); } // Binds the view model: type.Name = model.Name; type.DateLastModified = DateTime.Now; _dbContext.ProductTypes.Update(type); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(EditVM edit) { RecipeBL recipeBL = new RecipeBL(); HttpPostedFileBase file = Request.Files["FileUpload"]; if (file != null && file.ContentLength > 0) { if (file.ContentType.Equals("image/jpeg") || file.ContentType.Equals("image/png")) { //Save the File. string filePath = Server.MapPath("~/Images/") + file.FileName; file.SaveAs(filePath); edit.Recipe.ImgName = file.FileName; } else { ModelState.AddModelError("FormatError", "System obsługuje tylko pliki jpg i png!!"); return(View(edit)); } } recipeBL.EditRecipe(edit.Recipe); return(RedirectToAction("UserRecipes")); }
// GET: User/Edit/5 public ActionResult Edit(int id) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } if (!HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser").IsAdmin) { return(RedirectToAction("Login", "Home")); } using RestaurantManagerContext context = new RestaurantManagerContext(); User item = context.Users.Find(id); EditVM model = new EditVM { Id = item.Id, Username = item.Username, Email = item.Email, IsAdmin = item.IsAdmin }; return(View(model)); }
public ActionResult Create() { EditVM model = new EditVM(); model.SubRedditsList = new List <SelectListItem>(); model.UserId = AuthManager.LoggedUser.Id; SubRedditsRepository subRedditsRepo = new SubRedditsRepository(); List <SubReddit> subscribedSubReddits = subRedditsRepo.GetMySubscribes(AuthManager.LoggedUser.Id).ToList(); foreach (SubReddit subReddit in subscribedSubReddits) { model.SubRedditsList.Add( new SelectListItem() { Value = subReddit.Id.ToString(), Text = "r/" + subReddit.Name, Selected = subReddit.Id == model.SelectedSubReddit, Disabled = (((AuthManager.LoggedUser.BannedInSubReddits.Any(sr => sr.Id == subReddit.Id && sr.BannedUsers.Any(u => u.Id == AuthManager.LoggedUser.Id))) || (AuthManager.LoggedUser.MutedInSubReddits.Any(sr => sr.Id == subReddit.Id && sr.MutedUsers.Any(u => u.Id == AuthManager.LoggedUser.Id))))) ? true : false }); } return(PartialView("~/Views/Partials/Edits/_CreatePost.cshtml", model)); }
public PartialViewResult EditFastRoomRequest(QUANLY_PHONGHOP item) { AssignUserInfo(); DM_NGUOIDUNGBusiness = Get <DM_NGUOIDUNGBusiness>(); QUANLY_PHONGHOPBusiness = Get <QUANLY_PHONGHOPBusiness>(); QUANLY_PHONGHOP roomEntity; if (item.ID > 0) { roomEntity = QUANLY_PHONGHOPBusiness.Find(item.ID) ?? new QUANLY_PHONGHOP(); } else { if (item.GIOBATDAU >= 8 && item.GIOBATDAU < 23) { item.GIOKETTHUC = item.GIOBATDAU + 1; } else if (item.GIOBATDAU < 8) { item.GIOBATDAU = 8; item.GIOKETTHUC = item.GIOBATDAU + 1; } else { item.GIOKETTHUC = item.GIOBATDAU; } roomEntity = item; } EditVM viewModel = new EditVM(roomEntity); viewModel.groupLeaders = DM_NGUOIDUNGBusiness.GetDropDownByDeptParentId(currentUser.DeptParentID.GetValueOrDefault(), roomEntity.USER_ID); return(PartialView("EditPhong", viewModel)); }
public ActionResult Edit(int id) { PostsRepository repo = new PostsRepository(); Post item = repo.GetById(id); EditVM model = new EditVM(item); model.SubRedditsList = new List <SelectListItem>(); SubRedditsRepository subRedditsRepo = new SubRedditsRepository(); List <SubReddit> subscribedSubReddits = subRedditsRepo.GetMySubscribes(AuthManager.LoggedUser.Id).ToList(); foreach (SubReddit subReddit in subscribedSubReddits) { if (!(AuthManager.LoggedUser.BannedInSubReddits.Any(sr => sr.BannedUsers.Any(u => u.Id == AuthManager.LoggedUser.Id)) || AuthManager.LoggedUser.MutedInSubReddits.Any(sr => sr.MutedUsers.Any(u => u.Id == AuthManager.LoggedUser.Id)))) { model.SubRedditsList.Add( new SelectListItem() { Value = subReddit.Id.ToString(), Text = subReddit.Name, Selected = subReddit.Id == model.SelectedSubReddit }); } } //model.SubRedditId = model.SelectedSubReddit; return(PartialView("~/Views/Partials/Edits/_EditPost.cshtml", model)); }
// GET: User/Edit/5 public ActionResult Edit(int id) { if (HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser") == null) { return(RedirectToAction("Login", "Home")); } if (!HttpContext.Session.GetObjectFromJson <LoggedUser>("loggedUser").IsAdmin) { return(RedirectToAction("Login", "Home")); } using ToDoManagerContext context = new ToDoManagerContext(); User item = context.Users.Find(id); EditVM model = new EditVM { Id = item.Id, Username = item.Username, Password = item.Password, FirstName = item.FirstName, LastName = item.LastName }; return(View(model)); }
public virtual ActionResult Edit(object id, int?tabFocus) { id = Server.UrlDecode(id.ToString()); id = Convert.ChangeType(id, LinqToSqlUtils.GetPKPropertyInfo( MetaData.EntityType).PropertyType); var obj = Repository.GetByPK(id); if (obj == null) { return(Content("ќбъект не найден")); } var editVM = new EditVM(obj, MetaData); AddExtraControls(editVM, false); /* if(tabFocus.HasValue) * { * for (int i = 0; i < editVM.MetaData.ExtraControls.Count; i++) * { * var control = editVM.MetaData.ExtraControls[i]; * if (control.DisplayName.GetHashCode() == tabFocus) * editVM.TabFocus = i + 1; * } * }*/ editVM.SiteUrl = Html.GetUrlFor(obj); SetSiteObject(id, editVM); return(View("Edit", editVM)); }