protected void Page_Load(object sender, EventArgs e) { Context1 = new MSSQLLocalDBEntities(); if (IsPostBack) { return; } var habitLogsAux = from habiLog in Context1.HabitLogs group habiLog by habiLog.HabitId into g select g.FirstOrDefault(res => res.DoneDate == g.Max(sub => sub.DoneDate)); HabitLogs = habitLogsAux.ToList(); var nowx = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); Habits = Context1.Habits.ToList <Habit>().Where(p => p.DoneDate > nowx && p.Done) .OrderByDescending(h => h.DoneDate) .ToList(); var habitAndDescritionsAux = from habit in Habits join habitLog in HabitLogs on habit.Id equals habitLog.HabitId select new HabitAndDescrition { HabitId = habit.Id, HabitLogDescription = habitLog.ChangeDescription, Name = habit.Name, DoneDate = habitLog.DoneDate, ImgUrl = habit.Image }; HabitsAndLogs = habitAndDescritionsAux.ToList(); }
protected void Page_Load(object sender, EventArgs e) { Context1 = new MSSQLLocalDBEntities(); var id = Request.QueryString["Id"]; var action = Request.QueryString["action"]; if (!string.IsNullOrEmpty(id)) { var habit = Context1.Habits.First(p => p.Id.ToString() == id); if (action == "done") { habit.Done = true; habit.DoneDate = DateTime.Now; } else { habit.Done = false; } Context1.SaveChanges(); } if (!IsPostBack) { Habits1 = Context1.Habits.ToList <Habit>().OrderBy(h => h.HabitTime).ToList(); } }
protected void Page_Load(object sender, EventArgs e) { _context1 = new MSSQLLocalDBEntities(); if (!Page.IsPostBack) { this.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { _context = new MSSQLLocalDBEntities(); _id = Request.QueryString["Id"]; if (_id == null) { Response.Redirect("Default.aspx"); } Habit1 = _context.Habits.First(p => p.Id.ToString() == _id); _habitLogs = _context.HabitLogs.Where(p => p.HabitId == Habit1.Id).OrderByDescending(h => h.DoneDate) .ToList <HabitLog>(); }
protected void Page_Load(object sender, EventArgs e) { _context = new MSSQLLocalDBEntities(); if (IsPostBack) { return; } var nowx = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); SetHabits(_context.Habits.ToList <Habit>().Where(p => p.DoneDate < nowx || !p.Done).OrderByDescending(h => h.HabitLogCount) .ToList()); DoneHabits = _context.Habits.ToList <Habit>().Where(p => p.DoneDate > nowx && p.Done) .OrderByDescending(h => h.DoneDate).ToList(); }
protected void Page_Load(object sender, EventArgs e) { Context1 = new MSSQLLocalDBEntities(); var id = Request.QueryString["Id"]; if (id == null) { Response.Redirect("Default.aspx"); } if (IsPostBack) { return; } Habit1 = Context1.Habits.First(p => p.Id.ToString() == id); habitName.Text = Habit1.Name; habitImage.Text = Habit1.Image; habitTime.Text = Habit1.getHabitTimeStr(); description.Text = Habit1.Description; }
protected void Page_Load(object sender, EventArgs e) { Context1 = new MSSQLLocalDBEntities(); Habits = Context1.Habits.ToList <Habit>() .OrderByDescending(h => h.DoneDate) .ToList(); var habitAndDescritionsAux = from habit in Habits join habitLogX in Context1.HabitLogs on habit.Id equals habitLogX.HabitId select new HabitAndDescrition { HabitId = habit.Id, HabitLogDescription = habitLogX.ChangeDescription, Name = habit.Name, DoneDate = habitLogX.DoneDate, ImgUrl = habit.Image }; HabitsAndLogs = habitAndDescritionsAux.OrderByDescending(i => i.DoneDate).ToList(); }
protected void Page_Load(object sender, EventArgs e) { Context1 = new MSSQLLocalDBEntities(); var id = Int32.Parse(Request.QueryString["Id"]); if (id == 0) { Response.Redirect("Default.aspx"); } if (IsPostBack) { return; } List <HabitLog> habitLogsAux = Context1.HabitLogs.Where(p => p.HabitId == id).OrderByDescending(h => h.DoneDate).ToList <HabitLog>(); HabitLogs = habitLogsAux.ToList(); Habits = Context1.Habits.ToList <Habit>().Where(p => p.Id == id) .OrderByDescending(h => h.DoneDate) .ToList(); var habitAndDescritionsAux = from habit in Habits join habitLog in HabitLogs on habit.Id equals habitLog.HabitId select new HabitAndDescrition { HabitId = habit.Id, HabitLogDescription = habitLog.ChangeDescription, Name = habit.Name, DoneDate = habitLog.DoneDate, ImgUrl = habit.Image }; HabitsAndLogs = habitAndDescritionsAux.ToList(); }
public static void LogBeforeSave(Habit habit, TypeUpdate typeUpdate, HabitField field, object newValue, string logDescription, MSSQLLocalDBEntities context) { var habitLog = new HabitLog { ChangeDescription = logDescription, DoneDate = DateTime.Now, HabitId = habit.Id }; switch (field) { case HabitField.Name: habitLog.OldValue = habit.Name; break; case HabitField.DoneDate: habitLog.OldValue = habit.DoneDate?.ToString(); break; case HabitField.NewRecord: break; case HabitField.DeleteRecord: break; default: habitLog.OldValue = ""; break; } habitLog.NewValue = newValue.ToString(); context.HabitLogs.Add(habitLog); context.SaveChanges(); }