public ActionResult Create(User user) { if (ModelState.IsValid) { user.CreateUser = DateTime.Now; try { db.Users.Add(user); db.SaveChanges(); if (user.IsStudent) { UserHelper.CreateUserASP(user.UserName, "Student"); } if (user.IsTeacher) { UserHelper.CreateUserASP(user.UserName, "Teacher"); } if (user.FilePhoto != null) { var folder = "~/Content/Photos/Users"; var name = string.Format("{0}.Jpg", user.UserId); var response = FileHelper.UploadPhoto(user.FilePhoto, folder, name); if (response) { var pic = string.Format("{0}/{1}", folder, name); user.Photo = pic; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError(string.Empty, "Se produjo un Error a la Hora de Registrar este usuario"); } } return(View(user)); }
public ActionResult Edit(Department department) { if (ModelState.IsValid) { DuplicateAdministrators(department); } if (ModelState.IsValid) { try { db.Entry(department).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError(string.Empty, "Se produjo un Error a la hora de Editar el departamento"); } } ViewBag.UserId = new SelectList(ComboHelper.GetTeacher(), "UserId", "FullName", department.UserId); return(View(department)); }
public ActionResult Create(Group group) { if (ModelState.IsValid) { try { db.Groups.Add(group); db.SaveChanges(); if (group.FilePhoto != null) { var folder = "~/Content/Photos/Groups"; var name = string.Format("{0}.Jpg", group.GroupId); var response = FileHelper.UploadPhoto(group.FilePhoto, folder, name); if (response) { var pic = string.Format("{0}/{1}", folder, name); group.Photo = pic; db.Entry(group).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError(string.Empty, "Se produjo un Error a la Hora de Registrar este grupo"); } } ViewBag.CourseID = new SelectList(ComboHelper.GetCourse(), "CourseId", "Title", group.CourseID); ViewBag.UserId = new SelectList(ComboHelper.GetTeacher(), "UserId", "FullName", group.UserId); return(View(group)); }
public ActionResult Edit(Course course) { if (ModelState.IsValid) { try { db.Entry(course).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError(string.Empty, "Se produjo un Error a la Hora de editar este curso"); } } ViewBag.DepartmentId = new SelectList(ComboHelper.GetDepartment(), "DepartmentId", "Name", course.DepartmentId); return(View(course)); }