Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 public void Insert(UserBindingModel model)
 {
     using (var context = new JournalDb())
     {
         context.Users.Add(CreateModel(model, new User()));
         context.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public void Insert(GroupBindingModel model)
 {
     using (var context = new JournalDb())
     {
         context.Groups.Add(CreateModel(model, new Group()));
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public void Insert(MarksBindingModel model)
 {
     using (var context = new JournalDb())
     {
         context.Marks.Add(CreateModel(model, new Marks()));
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public void Insert(RoleBindingModel model)
 {
     using (var context = new JournalDb())
     {
         context.Roles.Add(CreateModel(model, new Role()));
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public void Insert(DisciplineBindingModel model)
 {
     using (var context = new JournalDb())
     {
         context.Disciplines.Add(CreateModel(model, new Discipline()));
         context.SaveChanges();
     }
 }
Exemplo n.º 9
0
 public List <RoleViewModel> GetFullList()
 {
     using (var context = new JournalDb())
     {
         return(context.Roles
                .Select(rec => new RoleViewModel
         {
             Id = rec.Id,
             NameRole = rec.NameRole
         })
                .ToList());
     }
 }
Exemplo n.º 10
0
 public List <GroupViewModel> GetFullList()
 {
     using (var context = new JournalDb())
     {
         return(context.Groups
                .Select(rec => new GroupViewModel
         {
             Id = rec.Id,
             NameGroup = rec.NameGroup
         })
                .ToList());
     }
 }
Exemplo n.º 11
0
        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();
            }
        }
Exemplo n.º 12
0
        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();
            }
        }
Exemplo n.º 13
0
        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();
            }
        }
Exemplo n.º 14
0
        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();
            }
        }
Exemplo n.º 15
0
        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();
            }
        }
Exemplo n.º 16
0
 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());
     }
 }
Exemplo n.º 17
0
 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());
     }
 }
Exemplo n.º 18
0
        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);
            }
        }
Exemplo n.º 19
0
 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());
     }
 }
Exemplo n.º 20
0
        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);
            }
        }
Exemplo n.º 21
0
        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);
            }
        }