public ActionResult AddQuestionToLine(int questionID, string selectedText, int?examContentId = 0) { var underlineText = new SATWritingUnderlineText(); underlineText.QuestionID = questionID; underlineText.UnderlineText = selectedText; underlineText.Number = db.SATQuestions.Find(questionID).QuestionNo; db.SATWritingUnderlineTexts.Add(underlineText); var _question = db.SATQuestions.Find(questionID); if (examContentId != 0) { _question.ExamContentID = examContentId; } else { if (Session["QuestionID"] != null) { Session["QuestionID"] = Session["QuestionID"].ToString() + questionID + ","; } else { Session["QuestionID"] = questionID; } } db.Entry(_question).State = EntityState.Modified; db.SaveChanges(); var question = db.SATQuestions.Where(q => q.ID == questionID); var countListQuestion = db.SATQuestions.Where(q => q.ExamContentID == null && q.SATWritingUnderlineTexts.Any(u => u.QuestionID == q.ID) == false).Except(question).Count(); var inputHidden = "<input type = 'hidden' id = 'questionID' name='questionToAdd' value = '" + questionID + "' />"; return(Json(new { countListQuestion = countListQuestion, inputHidden = inputHidden, number = underlineText.Number }, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit([Bind(Include = "ID,Direction,Title,Duration,NumberQuestion,TypeID,ExamCode")] SATExamForm sATExamForm) { if (ModelState.IsValid) { sATExamForm.Section = sATExamForm.TypeID; db.Entry(sATExamForm).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TypeID = new SelectList(db.SATTypes, "TypeID", "TypeName", sATExamForm.TypeID); return(View(sATExamForm)); }
public ActionResult Edit([Bind(Include = "StudentId,FirstName,LastName,Major,Address,City,State,ZipCode,Phone,Email,PhotoUrl,SSID")] Student student, HttpPostedFileBase Photo) { if (ModelState.IsValid) { if (Photo != null) { string imgName = Photo.FileName; string ext = imgName.Substring(imgName.LastIndexOf(".")); string[] goodExts = new string[] { ".jpeg", ".jpg", ".gif", ".png" }; if (goodExts.Contains(ext.ToLower())) { //imgName = Guid.NewGuid() + ext; Photo.SaveAs(Server.MapPath("~/Content/images/" + imgName)); string currentFile = Request.Params["PhotoUrl"]; if (currentFile != null && currentFile != "person-placeholder.jpg" && currentFile.Length != 0) { //uncomment when deployed to test delete System.IO.File.Delete(Server.MapPath("~/Content/images/" + currentFile)); } } student.PhotoUrl = imgName; } db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SSID = new SelectList(db.StudentStatuses, "SSID", "SSName", student.SSID); return(View(student)); }
public ActionResult Edit([Bind(Include = "ID,Link,Title,Status,CatId,Description,CreateDate,Thumbnail")] TutorialVideo tutorialVideo) { if (ModelState.IsValid) { if (Request.Files.Count > 0) { var uploadFile = Request.Files[0]; if (uploadFile.ContentLength > 0) { var fileName = Path.GetFileName(uploadFile.FileName); fileName = Guid.NewGuid() + Path.GetExtension(fileName); var file_src = Path.Combine(Server.MapPath("~/photo/Uploads/"), fileName); tutorialVideo.Thumbnail = fileName; uploadFile.SaveAs(file_src); } } db.Entry(tutorialVideo).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } SetCatInfo(); return(View(tutorialVideo)); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { using (var db = new SATEntities()) { var user = db.Users.FirstOrDefault(a => a.Email == model.Email && (a.IsDeleted == null || a.IsDeleted == false)); if (user != null) { user.ResetPasswordToken = Models.Utils.Instance.RandomString(10); db.Entry <User>(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); var resetUrl = string.Format("{0}/Account/ResetPassword", Request.Url.GetLeftPart(UriPartial.Authority)); MailServices mailServices = new MailServices(); var body = string.Format("Chào bạn, \r\n Một yêu cầu thiết lập lại mật khẩu đã được gửi đến địa chỉ {0}.\r\n Đây là mã xác thực: {2}\r\n Dưới đây là link thiết lập lại mật khẩu \r\n " + "{1}" + "\r\n Nếu không phải bạn gửi yêu cầu, làm ơn bỏ qua thư này.", model.Email, resetUrl, user.ResetPasswordToken); var mailModel = new MailModel { Subject = "Thiết lập lại mật khẩu", Body = body, To = model.Email }; await mailServices.SendAsync(mailModel); ViewBag.ResponseMessage = "Yêu cầu thiết lập lại mật khẩu của bạn đã được gửi đi,\r\n vui lòng kiểm tra thư điện tử của bạn."; } } } return(View()); }
public virtual void Update(T entity) { if (entity != (T)null) { dbset.Attach(entity); dataContext.Entry(entity).State = EntityState.Modified; } else { //LoggerFactory.CreateLog() // .LogInfo(String.Format("Cannot remove null entity into {0} repository", typeof(T).ToString())); } }
public ActionResult Edit([Bind(Include = "ID,AnswerContent,Mark,IsRightAnswer,Status,QuestionID,AnswerType")] SATAnswer sATAnswer) { try { var listQuestion = db.SATQuestions.ToList(); ViewBag.QuestionID = new SelectList(listQuestion, "ID", "Title", sATAnswer.QuestionID); var textType = new SelectListItem() { Value = "1", Text = "Nhập vào" }; var choiceType = new SelectListItem() { Value = "0", Text = "Chọn câu" }; ViewBag.AnswerType = new SelectList(new List <SelectListItem>() { choiceType, textType }, "Value", "Text", sATAnswer.AnswerType); ViewBag.QuestionID = new SelectList(db.SATQuestions, "ID", "Title", sATAnswer.QuestionID); if (ModelState.IsValid) { var answEntity = db.SATAnswers.Find(sATAnswer.ID); var maxAnswerQuestion = db.SATQuestions.Find(sATAnswer.QuestionID).SATAnswers.Count(); if (maxAnswerQuestion >= 4) { if (answEntity.QuestionID != sATAnswer.QuestionID) { ModelState.AddModelError("MaxAnswerError", "Câu hỏi này đã có đủ đáp án cần thiết, hãy chọn lại"); return(View(sATAnswer)); } } db.Entry(answEntity).CurrentValues.SetValues(sATAnswer); db.Entry(answEntity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sATAnswer)); } catch (Exception ex) { return(View(sATAnswer)); } }
public ActionResult Edit([Bind(Include = "SSID,SSName,SSdescription")] StudentStatus studentStatus) { if (ModelState.IsValid) { db.Entry(studentStatus).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(studentStatus)); }
public ActionResult Edit([Bind(Include = "SCSID,SCSName")] ScheduledClassStatus scheduledClassStatus) { if (ModelState.IsValid) { db.Entry(scheduledClassStatus).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(scheduledClassStatus)); }
public ActionResult Edit([Bind(Include = "CourseId,CourseName,CourseDescription,CreditHours,Curriculum,Notes,IsActive")] Cours cours) { if (ModelState.IsValid) { db.Entry(cours).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cours)); }
public ActionResult Edit([Bind(Include = "carg_Id,carg_Descripcion,carg_UsuarioCrea,carg_FechaCrea,carg_UsuarioModifica,carg_FechaModifica")] tbCargos tbCargos) { if (ModelState.IsValid) { db.Entry(tbCargos).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbCargos)); }
public ActionResult Edit([Bind(Include = "CourseID,CourseName,Subject,Description,CreditHours,IsVirtual")] Course course) { if (ModelState.IsValid) { db.Entry(course).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(course)); }
public ActionResult Edit([Bind(Include = "ScheduledClassID,CourseID,InstructorName,Location,StartDate,EndDate,EnrollmentMax")] ScheduledClass scheduledClass) { if (ModelState.IsValid) { db.Entry(scheduledClass).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CourseID = new SelectList(db.Courses, "CourseID", "CourseName", scheduledClass.CourseID); return(View(scheduledClass)); }
public ActionResult Edit([Bind(Include = "emp_Id,emp_Identidad,emp_Nombres,emp_Apellidos,emp_FechaNacimiento,emp_Sexo,emp_Direccion,mun_Id,emp_CorreoElectronico,emp_Telefono,carg_Id,emp_FechaIngreso,emp_FechadeSalida,emp_RazonSalida,emp_UsuarioCrea,emp_FechaCrea,emp_UsuarioModifica,emp_FechaModifica")] tbEmpleados tbEmpleados) { if (ModelState.IsValid) { db.Entry(tbEmpleados).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.carg_Id = new SelectList(db.tbCargos, "carg_Id", "carg_Descripcion", tbEmpleados.carg_Id); return(View(tbEmpleados)); }
public ActionResult Edit([Bind(Include = "car_Id,car_Descripcion,car_Encargado,car_UsuarioCrea,car_FechaCrea,car_UsuarioModifica,car_FechaModifica")] tbCarreras tbCarreras) { if (ModelState.IsValid) { db.Entry(tbCarreras).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.car_Encargado = new SelectList(db.tbEmpleados, "emp_Id", "emp_Identidad", tbCarreras.car_Encargado); return(View(tbCarreras)); }
public ActionResult Edit([Bind(Include = "ID,RawValue,ScoreValue,TypeID")] SATScore sATScore) { if (ModelState.IsValid) { db.Entry(sATScore).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TypeID = new SelectList(db.SATTypes, "TypeID", "TypeName", sATScore.TypeID); return(View(sATScore)); }
public ActionResult Edit([Bind(Include = "StudentId,FirstName,LastName,Major,Address,City,State,ZipCode,Phone,Email,PhotoUrl,SSID")] Students students) { if (ModelState.IsValid) { db.Entry(students).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SSID = new SelectList(db.StudentStatuses, "SSID", "SSName", students.SSID); return(View(students)); }
public ActionResult Edit([Bind(Include = "EnrollmentId,StudentId,ScheduledClassId,EnrollmentDate")] Enrollment enrollment) { if (ModelState.IsValid) { db.Entry(enrollment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ScheduledClassId = new SelectList(db.ScheduledClasses, "ScheduledClassId", "InstructorName", enrollment.ScheduledClassId); ViewBag.StudentId = new SelectList(db.Students, "StudentID", "FirstName", enrollment.StudentId); return(View(enrollment)); }
public ActionResult Edit([Bind(Include = "jor_Id,jor_Descripcion,jor_UsuarioCrea,jor_FechaCrea,jor_UsuarioModifica,jor_FechaModifica")] tbJornadas tbJornadas) { tbJornadas.jor_FechaModifica = DateTime.Now; tbJornadas.jor_UsuarioModifica = 2; if (ModelState.IsValid) { db.Entry(tbJornadas).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbJornadas)); }
public ActionResult Delete(int id) { using (var db = new SATEntities()) { using (var dbTransaction = db.Database.BeginTransaction()) { try { var deleteEntity = db.SATQuestions.Find(id); //deleteEntity.Status = false; deleteEntity.IsDeleted = true; //disable relate answers var answers = db.SATAnswers.Where(a => a.QuestionID == id).ToList(); //delete underline text var underlines = db.SATWritingUnderlineTexts.Where(u => u.QuestionID == id).ToList(); foreach (var item in answers) { item.Status = false; db.Entry(item).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } db.SATWritingUnderlineTexts.RemoveRange(underlines); db.SaveChanges(); db.Entry(deleteEntity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); dbTransaction.Commit(); return(RedirectToAction("Index")); } catch (Exception) { dbTransaction.Rollback(); return(View("Index")); } } } }
public ActionResult Edit([Bind(Include = "grad_Id,grad_Descripcion,grad_UsuarioCrea,grad_FechaCrea,grad_UsuarioModifica,grad_FechaModifica")] tbGrados tbGrados) { tbGrados.grad_UsuarioModifica = 2; tbGrados.grad_FechaModifica = DateTime.Now; if (ModelState.IsValid) { db.Entry(tbGrados).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.grad_UsuarioCrea = new SelectList(db.tbUsuarios, "usu_Id", "usu_NombreUsuario", tbGrados.grad_UsuarioCrea); ViewBag.grad_UsuarioModifica = new SelectList(db.tbUsuarios, "usu_Id", "usu_NombreUsuario", tbGrados.grad_UsuarioModifica); return(View(tbGrados)); }
public ActionResult Edit([Bind(Include = "mun_Id,mun_Descripcion,mun_UsuarioCrea,mun_FechaCrea,mun_UsuarioModifica,mun_FechaModifica,dep_Id")] tbMunicipios tbMunicipios) { if (ModelState.IsValid) { tbMunicipios.mun_UsuarioCrea = 1; tbMunicipios.mun_FechaCrea = DateTime.Now; tbMunicipios.mun_FechaModifica = DateTime.Now; db.Entry(tbMunicipios).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.dep_Id = new SelectList(db.tbDepartamentos, "dep_Id", "dep_Descripcion", tbMunicipios.dep_Id); return(View(tbMunicipios)); }
public ActionResult Edit([Bind(Include = "StudentId,FirstName,LastName,Major,Address,City,State,ZipCode,Phone,Email,PhotoUrl,SSID")] Student student, HttpPostedFileBase studentPhoto) { if (ModelState.IsValid) { #region File Upload string file = student.PhotoUrl; if (studentPhoto != null) { file = student.PhotoUrl; string ext = file.Substring(file.LastIndexOf('.')); string[] goodExts = { ".jpg", ".jpeg", ".png", ".gif" }; if (goodExts.Contains(ext.ToLower()) && studentPhoto.ContentLength <= 4194304) { file = Guid.NewGuid() + ext; #region resize image string savePath = Server.MapPath("~/Content/images/StudentImages/"); //Making an object of type Image from a stream of bytes that are coming from //our HttpPosterFileBase object called bookCover //HttpPostedFileBase bookCover -> bytes -> Image -> convertedImage Image convertedImage = Image.FromStream(studentPhoto.InputStream); int maxImageSize = 500; int maxThumbSize = 100; imageService.ResizeImage(savePath, file, convertedImage, maxImageSize, maxThumbSize); #endregion if (student.PhotoUrl != null && student.PhotoUrl != "NoImage.png") { imageService.Delete(savePath, student.PhotoUrl); } student.PhotoUrl = file; } } #endregion db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SSID = new SelectList(db.StudentStatuses, "SSID", "SSName", student.SSID); return(View(student)); }
public ActionResult Edit([Bind(Include = "notd_Id,not_Id,notd_Acumulado1,notd_Examen1,notd_Acumulado2,notd_Examen2,notd_Acumulado3,notd_Examen3,notd_Acumulado4,notd_Examen4,notd_UsuarioCrea,notd_FechaCrea,notd_UsuarioModifica,notd_FechaModifica")] tbNotaDetalles tbNotaDetalles) { tbNotaDetalles.notd_UsuarioModifica = 2; tbNotaDetalles.notd_FechaModifica = DateTime.Now; if (ModelState.IsValid) { db.Entry(tbNotaDetalles).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.notd_UsuarioCrea = new SelectList(db.tbUsuarios, "usu_Id", "usu_NombreUsuario", tbNotaDetalles.notd_UsuarioCrea); ViewBag.notd_UsuarioModifica = new SelectList(db.tbUsuarios, "usu_Id", "usu_NombreUsuario", tbNotaDetalles.notd_UsuarioModifica); ViewBag.not_Id = new SelectList(db.tbNotas, "not_Id", "not_Id", tbNotaDetalles.not_Id); return(View(tbNotaDetalles)); }
public ActionResult Edit([Bind(Include = "esc_Id,esc_Codigo,esc_NombreEscuela,esc_Director,esc_Contacto,esc_Telefono,esc_Correo,mun_Id,esc_UsuarioCrea,esc_FechaCrea,esc_UsuarioModifica,esc_FechaModifica")] tbEscuelas tbEscuelas) { if (ModelState.IsValid) { db.Entry(tbEscuelas).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.esc_UsuarioCrea = new SelectList(db.tbUsuarios, "usu_Id", "usu_NombreUsuario", tbEscuelas.esc_UsuarioCrea); ViewBag.esc_UsuarioModifica = new SelectList(db.tbUsuarios, "usu_Id", "usu_NombreUsuario", tbEscuelas.esc_UsuarioModifica); ViewBag.esc_Contacto = new SelectList(db.tbEmpleados, "emp_Id", "emp_Identidad", tbEscuelas.esc_Contacto); ViewBag.esc_Director = new SelectList(db.tbEmpleados, "emp_Id", "emp_Identidad", tbEscuelas.esc_Director); ViewBag.mun_Id = new SelectList(db.tbMunicipios, "mun_Id", "mun_Descripcion", tbEscuelas.mun_Id); return(View(tbEscuelas)); }
public ActionResult Edit([Bind(Include = "Id,Name,Email,Phone")] User userModel) { try { var entity = db.Users.Find(userModel.Id); entity.Name = userModel.Name; entity.Email = userModel.Email; entity.Phone = userModel.Phone; db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { return(View(userModel)); } }
public ActionResult Edit(CategoryViewModel model, int id, FormCollection collection) { if (!ModelState.IsValid) { //var parents = _categoryRepo.GetMany(t => t.ParentId == null); //ViewBag.Parents = parents; List <Category> categories = GetListMenu(); ViewBag.Categories = categories; return(View(model)); } var catEntity = _categoryRepo.GetById(id); var category = Mapper.Map <CategoryViewModel, Category>(model); if (catEntity.ParentId != null) { var parentCat = _categoryRepo.Get(t => t.Id == category.ParentId); category.Controller = parentCat == null ? null : parentCat.Controller; } category.Position = collection.Get("CatPosition"); category.ModifiedDate = DateTime.Now; category.ModifiedBy = User.UserId; category.IsDeleted = false; category.SEOTitle = category.Name.ToSeoUrl(); if (collection.Get("isParent") != null && collection.Get("isParent") == "true") { category.ParentId = null; } if (collection.Get("DisplayType") != null) { category.DisplayType = collection.Get("DisplayType"); } // _categoryRepo.UpdateAndSubmit(category); using (var db = new SATEntities()) { var attachCat = db.Categories.Attach(category); db.Entry(attachCat).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("index")); }
public ActionResult Edit([Bind(Include = "StudentId,FirstName,LastName,Major,Address,City,State,ZipCode,Phone,Email,PhotoUrl,SSID")] Student student, HttpPostedFileBase studentImage) { if (ModelState.IsValid) { #region File Upload if (studentImage != null) { string file = studentImage.FileName; string ext = file.Substring(file.LastIndexOf('.')); string[] goodExts = { ".jpeg", ".jpg", ".png", ".gif" }; //check that the uploaded file ext is in our list of good file extensions if (goodExts.Contains(ext)) { //if valid ext, check file size <= 4mb (max by default from ASP.NET) if (studentImage.ContentLength <= 4194304) { //create a new file name using a guid //file = Guid.NewGuid() + ext; #region Resize Image string savePath = Server.MapPath("~/Content/img/studentimages/"); Image convertedImage = Image.FromStream(studentImage.InputStream); int maxImageSize = 500; int maxThumbSize = 100; ImageService.ResizeImage(savePath, file, convertedImage, maxImageSize, maxThumbSize); #endregion if (student.PhotoUrl != null && student.PhotoUrl != "NoImage.png") { string path = Server.MapPath("~/Content/img/studentimages/"); ImageService.Delete(path, student.PhotoUrl); } } } student.PhotoUrl = file; } #endregion db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SSID = new SelectList(db.StudentStatuses, "SSID", "SSName", student.SSID); return(View(student)); }
public ActionResult Edit([Bind(Include = "StudentId,FirstName,LastName,Major,Address,City,State,ZipCode,Phone,Email,PhotoUrl,SSID")] Student student, HttpPostedFileBase profilePic) { if (ModelState.IsValid) { #region Image Upload string imgName = "default.jpg"; if (profilePic != null) { string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" }; string ext = imgName.Substring(imgName.LastIndexOf('.')); if (goodExts.Contains(ext.ToLower())) { imgName = Guid.NewGuid() + ext; profilePic.SaveAs(Server.MapPath("~/Content/images/" + imgName)); } else { imgName = "default.jpg"; } } student.PhotoUrl = imgName; #endregion db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SSID = new SelectList(db.StudentStatuses, "SSID", "SSName", student.SSID); return(View(student)); }
public ActionResult Edit([Bind(Include = "StudentID,FirstName,LastName,DOB,Major,SSID,HasScholarship,Email,Address,City,State,Zip,EmergencyContact,EmergencyPhone,StudentPhone,StudentImage")] Student student, HttpPostedFileBase StudentImage) { if (ModelState.IsValid) { #region File Upload if (StudentImage != null) { string imgName = StudentImage.FileName; string ext = imgName.Substring(imgName.LastIndexOf(".")); string[] goodExtensions = { "jpeg", "jpg", "gif", "png" }; if (goodExtensions.Contains(ext.ToLower()) && (StudentImage.ContentLength < 4194304)) { imgName = Guid.NewGuid() + ext; StudentImage.SaveAs(Server.MapPath("~/Content/images/" + imgName)); } if (student.StudentImage != null && student.StudentImage != "noimg.jpg") { System.IO.File.Delete(Server.MapPath("~/Content/images/" + Session["currentImage"].ToString())); } } student.StudentImage = "imgName"; #endregion db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SSID = new SelectList(db.StudentStatuses, "SSID", "StatusName", student.SSID); return(View(student)); }