public JsonResult UnallocateAllRooms(bool name) { int schoolid = Convert.ToInt32(Session["school"]); var roomInfo = db.TimeTables.Where(r => r.AllocationStatus == "Allocated" && r.SchoolId == schoolid).ToList(); if (roomInfo.Count == 0) { return(Json(false)); } else { foreach (var room in roomInfo) { room.AllocationStatus = null; db.Entry(room).State = EntityState.Modified; db.SaveChanges(); } return(Json(true)); } }
public ActionResult Profile(tbl_ClientValidation sa) { Client client = new Client(); try { //loginTable l = new loginTable(); int userid = Convert.ToInt32((Session["Cliente"])); var l = db.loginTables.FirstOrDefault(t => t.UserId == userid); if (ModelState.IsValid) { if (sa != null) { if (l != null) { Session["ClientName"] = sa.UserName; l.UserId = userid; l.Name = sa.UserName; l.Password = sa.Password; l.Email = sa.Email; l.RoleID = 5; db.Entry(l).State = EntityState.Modified; db.SaveChanges(); } string filename = Path.GetFileNameWithoutExtension(sa.UserImageFIle.FileName); string extension = Path.GetExtension(sa.UserImageFIle.FileName); filename = DateTime.Now.ToString("yymmssff") + extension; client.Image = "~/Content/img/users/" + filename; client.UserName = sa.UserName; client.Email = sa.Email; client.Password = sa.Password; client.UserId = userid; if (extension.ToLower() == ".jpg" || extension.ToLower() == ".jpeg" || extension.ToLower() == ".png") { if (sa.UserImageFIle.ContentLength <= 1000000) { db.Entry(client).State = EntityState.Modified; string oldImgPath = Request.MapPath(Session["imgPath"].ToString()); if (db.SaveChanges() > 0) { filename = Path.Combine(Server.MapPath("~/Content/img/users/"), filename); sa.UserImageFIle.SaveAs(filename); if (System.IO.File.Exists(oldImgPath)) { System.IO.File.Delete(oldImgPath); } ViewBag.Message = "Data Updated"; return(RedirectToAction("Profile")); } } else { ViewBag.msg = "File Size must be Equal or less than 1mb"; } } else { ViewBag.msg = "Inavlid File Type"; } } //} else { client.Image = Session["imgPath"].ToString(); if (l != null) { Session["ClientName"] = sa.UserName; l.UserId = userid; l.Name = sa.UserName; l.Password = sa.Password; l.Email = sa.Email; l.RoleID = 5; db.Entry(l).State = EntityState.Modified; db.SaveChanges(); } client.UserName = sa.UserName; client.Email = sa.Email; client.Password = sa.Password; client.UserId = userid; db.Entry(client).State = EntityState.Modified; if (db.SaveChanges() > 0) { ViewBag.Message = "Data Updated"; return(RedirectToAction("Profile")); } } } } catch (Exception ex) { ViewBag.Message = "Not Updated"; return(View()); } return(View()); }
public JsonResult SaveAssignCourse(CourseAssignToTeacher assignCourse) { var asignCoursesList = db.CourseAssignToTeachers.Where(t => t.courseId == assignCourse.courseId && t.Course.Status == true).ToList(); if (asignCoursesList.Count > 0) { return(Json(false)); } else { int schoolid = Convert.ToInt32(Session["school"]); assignCourse.School_Id = schoolid; db.CourseAssignToTeachers.Add(assignCourse); db.SaveChanges(); var teacher = db.Teachers.FirstOrDefault(t => t.Id == assignCourse.TeacherId); var course = db.Courses.FirstOrDefault(t => t.courseId == assignCourse.courseId); if (course != null) { course.Status = true; course.AssignTo = teacher.Name; db.Entry(course).State = EntityState.Modified; //db.Courses.Add(course); db.SaveChanges(); return(Json(true)); } else { return(Json(false)); } //return Json(false); } }