public void DeleteComment(int commentId) { // This line is to find out the record by the id TODOLIST todo = ent.TODOLIST.Find(commentId); //This part is use for Delete ent.TODOLIST.Remove(todo); ent.SaveChanges(); }
public ViewResult Dashboard() { var CurrentUserId = User.Identity.GetUserId(); var allMessages = (from a in db.AspNetMessages join b in db.AspNetMessage_Receiver on a.Id equals b.MessageID where b.ReceiverID == CurrentUserId && b.Seen == "Not Seen" join c in db.AspNetUsers on a.SenderID equals c.Id select new { a.Message, a.Time, c.Name }).ToList(); List <Message> messages = new List <Message>(); foreach (var item in allMessages) { Message m = new Message(); m.Name = item.Name; m.message = item.Message; string monthName = item.Time.Value.ToString("MMM", CultureInfo.InvariantCulture); m.date = monthName + " " + item.Time.Value.Day + "," + item.Time.Value.Year; messages.Add(m); } ViewBag.Messages = messages; int classid = db.AspNetClasses.Where(m => m.TeacherID == CurrentUserId).Select(a => a.Id).FirstOrDefault(); ViewBag.allStudents = db.AspNetStudents.Where(m => m.ClassID == classid).Count(); ViewBag.TotalMessages = db.AspNetMessage_Receiver.Where(m => m.ReceiverID == CurrentUserId && m.Seen == "Not Seen").Count(); ViewBag.TotalNotifications = db.AspNetNotification_User.Where(m => m.UserID == CurrentUserId && m.Seen == false).Count(); var ty = (from a in db.AspNetClasses join b in db.AspNetHomeworks on a.Id equals b.ClassId where a.TeacherID == CurrentUserId && b.PrincipalApproved_status == "Rejected" select new { a.ClassName, b.Date, b.Id }).ToList().OrderByDescending(a => a.Date); List <TODOLIST> kjlk = new List <TODOLIST>(); foreach (var t in ty) { TODOLIST tyr = new TODOLIST(); tyr.Classname = t.ClassName; tyr.HomeWorkId = t.Id; if (t.Date.Value.Day + "/" + t.Date.Value.Month + "/" + t.Date.Value.Year != DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year) { tyr.isToDay = false; } else { tyr.isToDay = true; } tyr.date = t.Date.Value.Day + "/" + t.Date.Value.Month + "/" + t.Date.Value.Year; if (t.Date < DateTime.Now) { int ActualTime = (DateTime.Now - t.Date.Value.Date).Days; if (ActualTime == 1) { tyr.Actualdate = ActualTime + " day ago"; } else if (ActualTime >= 30) { int months = ActualTime / 30; if (months == 1) { tyr.Actualdate = months + " month ago"; } else { tyr.Actualdate = months + " months ago"; } } else { int weeks = ActualTime / 7; if (weeks == 0) { tyr.Actualdate = ActualTime + " days ago"; } else { if (weeks == 1) { tyr.Actualdate = weeks + " week ago"; } else { tyr.Actualdate = weeks + " weeks ago"; } } } } else { tyr.Actualdate = "Today"; } kjlk.Add(tyr); } ViewBag.ClassName = kjlk; return(View("BlankPage")); }
public void AddComment(TODOLIST todo) { ent.TODOLIST.Add(todo); ent.SaveChanges(); }
public ActionResult Dashboard() { var principalId = User.Identity.GetUserId(); var AllMessages = (from a in db.AspNetMessages join b in db.AspNetMessage_Receiver on a.Id equals b.MessageID where b.ReceiverID == principalId join c in db.AspNetUsers on a.SenderID equals c.Id select new { a.Message, a.Time, c.Name }).ToList(); List <Message> allMessages = new List <Message>(); foreach (var data in AllMessages) { Message m = new Message(); m.Name = data.Name; m.message = data.Message; string monthName = data.Time.Value.ToString("MMM", CultureInfo.InvariantCulture); m.date = monthName + " " + data.Time.Value.Day + "," + data.Time.Value.Year; allMessages.Add(m); } ViewBag.allPrincipalMessages = allMessages; ViewBag.TotalMessages = db.AspNetMessage_Receiver.Where(m => m.ReceiverID == principalId && m.Seen == "Not Seen").Count(); ViewBag.TotalUsers = (from uid in db.AspNetUsers join sid in db.AspNetStudents on uid.Id equals sid.StudentID where uid.Status != "False" select sid.StudentID).Count(); ViewBag.TotalNotifications = db.AspNetNotification_User.Where(m => m.UserID == principalId && m.Seen == false).Count(); var ty = (from classid in db.AspNetHomeworks join classname in db.AspNetClasses on classid.ClassId equals classname.Id where classid.PrincipalApproved_status == "Created" || classid.PrincipalApproved_status == "Edited" select new { classname.ClassName, classid.Date, classid.Id }).ToList().OrderByDescending(a => a.Date); List <TODOLIST> kjlk = new List <TODOLIST>(); foreach (var t in ty) { TODOLIST tyr = new TODOLIST(); tyr.Classname = t.ClassName; tyr.HomeWorkId = t.Id; if (t.Date.Value.Day + "/" + t.Date.Value.Month + "/" + t.Date.Value.Year != DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year) { tyr.isToDay = false; } else { tyr.isToDay = true; } tyr.date = t.Date.Value.Day + "/" + t.Date.Value.Month + "/" + t.Date.Value.Year; if (t.Date < DateTime.Now) { int ActualTime = (DateTime.Now - t.Date.Value.Date).Days; if (ActualTime == 1) { tyr.Actualdate = ActualTime + " day ago"; } else if (ActualTime >= 30) { int months = ActualTime / 30; if (months == 1) { tyr.Actualdate = months + " month ago"; } else { tyr.Actualdate = months + " months ago"; } } else { int weeks = ActualTime / 7; if (weeks == 0) { tyr.Actualdate = ActualTime + " days ago"; } else { if (weeks == 1) { tyr.Actualdate = weeks + " week ago"; } else { tyr.Actualdate = weeks + " weeks ago"; } } } } else { tyr.Actualdate = "Today"; } tyr.date = t.Date.Value.Day + "/" + t.Date.Value.Month + "/" + t.Date.Value.Year; kjlk.Add(tyr); } ViewBag.ClassName = kjlk; return(View("BlankPage")); }