public List <MarksViewModel> GetFilteredList(MarksBindingModel model) { if (model == null) { return(null); } using (var context = new JournalDb()) { return(context.Marks .Include(rec => rec.User) .Include(rec => rec.Discipline) .Where(rec => (!model.DateFrom.HasValue && !model.DateTo.HasValue && rec.Date.Date == model.Date.Date) || (model.DateFrom.HasValue && model.DateTo.HasValue && rec.Date.Date >= model.DateFrom.Value.Date && rec.Date.Date <= model.DateTo.Value.Date)) .ToList() .Select(rec => new MarksViewModel { Id = rec.Id, UserId = rec.UserId, DisciplineId = rec.DisciplineId, UserName = rec.User.UserName, DisciplineName = rec.Discipline.NameDiscipline, Mark = rec.Mark, Date = rec.Date, }) .ToList()); } }
public MarksViewModel GetElement(MarksBindingModel model) { if (model == null) { return(null); } using (var context = new JournalDb()) { var mark = context.Marks .Include(rec => rec.User) .Include(rec => rec.Discipline) .FirstOrDefault(rec => rec.Id == model.Id); return(mark != null ? new MarksViewModel { Id = mark.Id, UserId = mark.UserId, UserName = mark.User.UserName, DisciplineId = mark.DisciplineId, DisciplineName = mark.Discipline.NameDiscipline, Mark = mark.Mark, Date = mark.Date, } : null); } }
public UserViewModel GetElement(UserBindingModel model) { if (model == null) { return(null); } using (var context = new JournalDb()) { var user = context.Users .Include(rec => rec.Role) .Include(rec => rec.Group) .FirstOrDefault(rec => rec.Login == model.Login || rec.Id == model.Id); return(user != null ? new UserViewModel { Id = user.Id, RoleId = user.RoleId, NameRole = user.Role.NameRole, GroupId = user.GroupId.HasValue ? user.GroupId : null, NameGroup = user.GroupId.HasValue ? user.Group.NameGroup : string.Empty, UserName = user.UserName, Login = user.Login, Password = user.Password } : null); } }
public void Insert(UserBindingModel model) { using (var context = new JournalDb()) { context.Users.Add(CreateModel(model, new User())); context.SaveChanges(); } }
public void Insert(GroupBindingModel model) { using (var context = new JournalDb()) { context.Groups.Add(CreateModel(model, new Group())); context.SaveChanges(); } }
public void Insert(MarksBindingModel model) { using (var context = new JournalDb()) { context.Marks.Add(CreateModel(model, new Marks())); context.SaveChanges(); } }
public void Insert(RoleBindingModel model) { using (var context = new JournalDb()) { context.Roles.Add(CreateModel(model, new Role())); context.SaveChanges(); } }
public void Insert(DisciplineBindingModel model) { using (var context = new JournalDb()) { context.Disciplines.Add(CreateModel(model, new Discipline())); context.SaveChanges(); } }
public List <RoleViewModel> GetFullList() { using (var context = new JournalDb()) { return(context.Roles .Select(rec => new RoleViewModel { Id = rec.Id, NameRole = rec.NameRole }) .ToList()); } }
public List <GroupViewModel> GetFullList() { using (var context = new JournalDb()) { return(context.Groups .Select(rec => new GroupViewModel { Id = rec.Id, NameGroup = rec.NameGroup }) .ToList()); } }
public void Delete(UserBindingModel model) { using (var context = new JournalDb()) { var user = context.Users.FirstOrDefault(rec => rec.Id == model.Id); if (user == null) { throw new Exception("Пользователь не найден"); } context.Users.Remove(user); context.SaveChanges(); } }
public void Update(MarksBindingModel model) { using (var context = new JournalDb()) { var mark = context.Marks.FirstOrDefault(rec => rec.Id == model.Id); if (mark == null) { throw new Exception("Оценка не найдена"); } CreateModel(model, mark); context.SaveChanges(); } }
public void Delete(DisciplineBindingModel model) { using (var context = new JournalDb()) { var discipline = context.Disciplines.FirstOrDefault(rec => rec.Id == model.Id); if (discipline == null) { throw new Exception("Дисциплина не найдена"); } context.Disciplines.Remove(discipline); context.SaveChanges(); } }
public void Delete(RoleBindingModel model) { using (var context = new JournalDb()) { var role = context.Roles.FirstOrDefault(rec => rec.Id == model.Id); if (role == null) { throw new Exception("Должность не найдена"); } context.Roles.Remove(role); context.SaveChanges(); } }
public void Delete(GroupBindingModel model) { using (var context = new JournalDb()) { var group = context.Groups.FirstOrDefault(rec => rec.Id == model.Id); if (group == null) { throw new Exception("Группа не найдена"); } context.Groups.Remove(group); context.SaveChanges(); } }
public List <DisciplineViewModel> GetFullList() { using (var context = new JournalDb()) { return(context.Disciplines .Select(rec => new DisciplineViewModel { Id = rec.Id, NameDiscipline = rec.NameDiscipline, UserId = rec.UserId, NameUser = rec.User.UserName }) .ToList()); } }
public List <MarksViewModel> GetFullList() { using (var context = new JournalDb()) { return(context.Marks .Select(rec => new MarksViewModel { Id = rec.Id, UserId = rec.UserId, UserName = rec.User.UserName, DisciplineId = rec.DisciplineId, DisciplineName = rec.Discipline.NameDiscipline, Mark = rec.Mark, Date = rec.Date, }) .ToList()); } }
public RoleViewModel GetElement(RoleBindingModel model) { if (model == null) { return(null); } using (var context = new JournalDb()) { var role = context.Roles .FirstOrDefault(rec => rec.NameRole == model.NameRole || rec.Id == model.Id); return(role != null ? new RoleViewModel { Id = role.Id, NameRole = role.NameRole } : null); } }
public List <UserViewModel> GetFullList() { using (var context = new JournalDb()) { return(context.Users .Include(rec => rec.Role) .Include(rec => rec.Group) .Select(rec => new UserViewModel { Id = rec.Id, RoleId = rec.RoleId, NameRole = rec.Role.NameRole, GroupId = rec.GroupId.HasValue ? rec.GroupId : null, NameGroup = rec.GroupId.HasValue ? rec.Group.NameGroup : string.Empty, UserName = rec.UserName, Login = rec.Login, Password = rec.Password }) .ToList()); } }
public GroupViewModel GetElement(GroupBindingModel model) { if (model == null) { return(null); } using (var context = new JournalDb()) { var group = context.Groups .FirstOrDefault(rec => rec.NameGroup == model.NameGroup || rec.Id == model.Id); return(group != null ? new GroupViewModel { Id = group.Id, NameGroup = group.NameGroup } : null); } }
public DisciplineViewModel GetElement(DisciplineBindingModel model) { if (model == null) { return(null); } using (var context = new JournalDb()) { var discipline = context.Disciplines .Include(rec => rec.User) .FirstOrDefault(rec => rec.NameDiscipline == model.NameDiscipline || rec.Id == model.Id); return(discipline != null ? new DisciplineViewModel { Id = discipline.Id, NameDiscipline = discipline.NameDiscipline, UserId = discipline.UserId, NameUser = discipline.User.UserName } : null); } }