// GET: Department/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Department department = await db.Departments.FindAsync(id); if (department == null) { return(HttpNotFound()); } EditDepartmentViewModel model = new EditDepartmentViewModel { DepartmentID = department.DepartmentID, Name = department.Name, Budget = department.Budget, StartDate = department.StartDate, InstructorID = department.InstructorID, RowVersion = department.RowVersion }; ViewBag.InstructorID = new SelectList(db.Instructors, "ID", "FullName", model.InstructorID); return(View(model)); }
public async Task <IActionResult> Edit(EditDepartmentViewModel model) { if (ModelState.IsValid) { var teacher = await UserManager.FindByIdAsync(model.HeadTeacherId); string name = model.Name; var dep = await(from d in DBContext.Departments.Include(h => h.HeadTeacher) where d.Id.ToString() == model.DepartmentId select d).FirstOrDefaultAsync(); DBContext.Update(dep).Entity.HeadTeacher = teacher; DBContext.Update(dep).Entity.Name = name; await DBContext.SaveChangesAsync(); return(RedirectToAction("Index", new { InstId = model.InstitutionId })); } model.AvailableTeachers = await UserManager.GetUsersInRoleAsync("Teacher"); return(View(model)); }
public override ActionResult Edit(int Id) { var model = repository.FindById(Id); var viewModel = new EditDepartmentViewModel(); viewModel = mapper.Map <EditDepartmentViewModel>(model); return(View(viewModel)); }
public ActionResult Create() { var viewModel = new EditDepartmentViewModel { DepartmentId = 0, Name = "New Department" }; return(View("Edit", viewModel)); }
public ActionResult Edit(int departmentId) { Department storedDepartment = m_unitOfWork.Departments.Get(departmentId); var viewModel = new EditDepartmentViewModel { DepartmentId = storedDepartment.DepartmentId, Name = storedDepartment.Name }; return(View(viewModel)); }
public IActionResult GetDepartment(Guid departmentId) { var response = new EditDepartmentViewModel { Id = Guid.NewGuid(), AddedBy = "aaa", Description = "asssssddddddd ddd", Importance = 4, Title = "rrrr" }; return(Ok(response)); }
//[ValidateAntiForgeryToken] public ActionResult Edit(EditDepartmentViewModel editDepartmentViewModel) { DepartmentManager departementManager = new DepartmentManager(); var oldDepartment = departementManager.Read(editDepartmentViewModel.DepartmentID); oldDepartment.Name = editDepartmentViewModel.Name; oldDepartment.ParentDepartement = departementManager.Read(editDepartmentViewModel.ParentDepartmentGUID); departementManager.Update(oldDepartment); departementManager.saveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(EditDepartmentViewModel departmentVM) { try { Department department = new Department(); department.Id = departmentVM.Id; department.Name = departmentVM.Name; department.OrganaizationId = departmentVM.OrganaizationId; _departmentManager.Update(department); return(RedirectToAction("Index")); } catch { return(View()); } }
public IActionResult EditDepartment(EditDepartmentViewModel model) { try { if (ModelState.IsValid) { var department = _mapper.Map <Department>(model); _storeRepository.UpdateDepartment(department); _unitOfWork.Commit(); } return(RedirectToAction(nameof(this.ManageDepartments))); } catch { return(View()); } }
// GET: Department/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(HttpNotFound()); } Department department = _departmentManager.GetById((int)id); EditDepartmentViewModel departmentVM = new EditDepartmentViewModel() { Id = department.Id, Name = department.Name, OrganaizationId = department.OrganaizationId }; ViewBag.OrganaizationId = new SelectList(_organaizationManager.GetAll(), "Id", "Name", department.OrganaizationId); return(View(departmentVM)); }
public ActionResult EditDepartment(EditDepartmentViewModel editDepartment) { List <ApplicationUser> users = db.GetAllUsers().ToList(); editDepartment.Users = users; editDepartment.UserNames = db.GetAllUserNames().ToList(); Department department = db.GetDepartmentByID(editDepartment.CurrentDepartmentID); if (ModelState.IsValid) { department.Manager = db.GetUserByName(editDepartment.ManagerUserName); department.Name = editDepartment.Name; db.EditDepartment(department); return(RedirectToAction("Index")); } return(View(editDepartment)); }
public ActionResult Edit(EditDepartmentViewModel viewModel) { if (viewModel.DepartmentId == 0) { Department newDepartment = new Department { Name = viewModel.Name }; m_unitOfWork.Departments.Add(newDepartment); } else { Department storedDepartment = m_unitOfWork.Departments.Get(viewModel.DepartmentId); storedDepartment.Name = viewModel.Name; } m_unitOfWork.Complete(); return(RedirectToAction("Index")); }
// GET: Admin/EditDepartment/5 public ActionResult EditDepartment(int?id) { EditDepartmentViewModel editDepartment = new EditDepartmentViewModel(); editDepartment.Users = db.GetAllUsers(); editDepartment.UserNames = db.GetAllUserNames(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Department department = db.GetDepartmentByID(id.Value); editDepartment.Manager = department.Manager; editDepartment.CurrentDepartmentID = department.ID; editDepartment.Name = department.Name; if (department == null) { return(HttpNotFound()); } return(View(editDepartment)); }
public async Task <IActionResult> Edit(string Id) { var dep = await(from d in DBContext.Departments.Include(h => h.HeadTeacher) where d.Id.ToString() == Id select d).FirstOrDefaultAsync(); if (dep != null) { var inst = await(from i in DBContext.Institutions.Include(d => d.Departments) where i.Departments.Contains(dep) select i).FirstOrDefaultAsync(); var model = new EditDepartmentViewModel() { Name = dep.Name, DepartmentId = dep.Id.ToString(), HeadTeacherId = dep.HeadTeacher.Id, InstitutionId = inst.Id.ToString(), InstitutionName = inst.Name, AvailableTeachers = await UserManager.GetUsersInRoleAsync("Teacher"), userGrants = await checkService.getUserGrants(User) }; return(View(model)); } return(View());//вряд-ли это произойдет, но я вообще хз, что тогда случится }
public ActionResult Edit(//[Bind(Include = "DepartmentID, Name, RowVersion")] EditDepartmentViewModel viewModel, int Id) { Department department = new Department(); try { department = mapper.Map <Department>(viewModel); if (ModelState.IsValid) { repository.Update(department); repository.Save(); return(RedirectToAction("index", "Department")); } } catch (DbUpdateConcurrencyException ex) { var entry = ex.Entries.Single(); var clientValues = (Department)entry.Entity; var databaseValues = (Department)entry.GetDatabaseValues().ToObject(); if (databaseValues.Name != clientValues.Name) { ModelState.AddModelError("Name", "Current value: " + databaseValues.Name); } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to edit this record, click " + "the Save button again. Otherwise click the Back to List hyperlink."); viewModel.RowVersion = databaseValues.RowVersion; } return(View(viewModel)); }
public async Task <ActionResult> Edit(EditDepartmentViewModel model) { try { if (ModelState.IsValid) { Department department = await db.Departments.FindAsync(model.DepartmentID); if (department == null) { ModelState.AddModelError("", "Unable to save changes. The department was deleted by another User."); ViewBag.InstructorID = new SelectList(db.Instructors, "ID", "FullName", model.InstructorID); return(View(model)); } if (department.RowVersion.SequenceEqual(model.RowVersion)) { department.Name = model.Name; department.Budget = model.Budget; department.StartDate = model.StartDate; department.InstructorID = model.InstructorID; db.Entry(department).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } else { if (department.Name != model.Name) { ModelState.AddModelError("Name", "Current Value: " + department.Name); } if (department.Budget != model.Budget) { ModelState.AddModelError("Budget", "Current Value: " + String.Format("{0:c}", department.Budget)); } if (department.StartDate != model.StartDate) { ModelState.AddModelError("StartDate", "Current Value: " + String.Format("{0:yyyy-MM-dd}", department.StartDate)); } if (department.InstructorID != model.InstructorID) { ModelState.AddModelError("InstructorID", "Current Value: " + db.Instructors.Find(department.InstructorID).FullName); } ModelState.AddModelError("", "The record you attempted to edit was modified by another User after you got the original value. The edit operation was cancelled and the current values in the database have been displayed. If you still want to edit this record, click the Save button again. Otherwise click the 'Back To List' hyperlink."); model.RowVersion = department.RowVersion; } } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } ViewBag.InstructorID = new SelectList(db.Instructors, "ID", "FullName", model.InstructorID); return(View(model)); }