public async Task <SingleAgenda> GetAgendaById(int id) { SingleAgenda li = new SingleAgenda(); try { Agendas agenda = await db.Agendas.FindAsync(id); if (agenda == null) { li.Status = false; li.Message = "404 Not Found"; return(li); } else { li.Status = true; li.Message = "Record you asked."; AgendasClass temp = new AgendasClass { ID = agenda.ID, Title = agenda.Title, DateTime = agenda.DateTime.ToString("dddd dd MMMM, yyyy") + " at " + agenda.DateTime.ToShortTimeString(), Description = agenda.Description, Users = db.AgendaUsers.Where(x => x.AgendasID == agenda.ID).Count() }; if (agenda.DateTime == DateTime.Now) { temp.Status = "Today"; temp.Color = "0xff38ad0d"; } else if (agenda.DateTime < DateTime.Now) { temp.Status = "Hosted"; temp.Color = "0xffb7b7b7"; } else { temp.Status = "Upcoming"; temp.Color = "0xfff47d08"; } li.Agenda = temp; li.Note = await db.Notes.Select(x => new { x.ID, x.Title, x.Description, x.AgendasID, MemberId = x.Peoples.ID, MemberImage = x.Peoples.Image, MemberName = x.Peoples.FullName, UserType = x.Peoples.Type, NoteStatus = x.Status }).FirstOrDefaultAsync(x => x.AgendasID == agenda.ID && x.NoteStatus.Equals("Public")); li.Secretary = db.Peoples.Where(x => x.Type.Equals("Secretary")).Select(x => new { x.ID, x.Image, x.FullName, x.Email }).ToList(); li.Members = db.AgendaUsers.Where(x => x.AgendasID == agenda.ID && x.Status == true).Take(4).Select(x => new { MemberId = x.Peoples.ID, MemberImage = x.Peoples.Image, MemberName = x.Peoples.FullName, MemberEmail = x.Peoples.Email }).ToList(); return(li); } } catch (Exception e) { li.Status = false; li.Message = e.InnerException.ToString(); return(li); } }
// Get All Agendas: Admin public ResponseList GetAgendas(int?page = 1, int?per_page = 10, string search = "") { ResponseList li = new ResponseList(); try { List <Agendas> data = new List <Agendas>(); if (page.Value <= 0) { page = 1; } int pg = (page.Value - 1); var skip = pg * per_page.Value; li.Status = true; li.Message = "List of Agendas"; if (String.IsNullOrWhiteSpace(search)) { data = db.Agendas.OrderBy(x => x.DateTime).Skip(skip).Take(per_page.Value).ToList(); } else { data = db.Agendas.Where(x => x.Title.Contains(search)).OrderBy(x => x.DateTime).Skip(skip).Take(per_page.Value).ToList(); } List <AgendasClass> list1 = new List <AgendasClass>(); List <AgendasClass> list2 = new List <AgendasClass>(); List <AgendasClass> list3 = new List <AgendasClass>(); foreach (var details in data) { AgendasClass temp = new AgendasClass { ID = details.ID, Title = details.Title, DateTime = details.DateTime.ToString("dddd dd MMMM, yyyy") + " at " + details.DateTime.ToShortTimeString(), Description = details.Description, Users = db.AgendaUsers.Where(x => x.AgendasID == details.ID).Count() }; if (details.DateTime.Day == DateTime.Today.Day && details.DateTime.Year == DateTime.Today.Year && details.DateTime.Month == DateTime.Today.Month) { temp.Status = "Today"; temp.Color = "0xff38ad0d"; list1.Add(temp); } else if (details.DateTime > DateTime.Today) { temp.Status = "Upcoming"; temp.Color = "0xfff47d08"; list2.Add(temp); } else { temp.Status = "Hosted"; temp.Color = "0xffb7b7b7"; list3.Add(temp); } } li.Data = list1.Concat(list2).Concat(list3).ToList(); return(li); } catch (Exception e) { li.Status = false; li.Message = e.InnerException.ToString(); return(li); } }