Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("Id,Name,DateStart,DateFinish,Specialty,Course")] StudentsGroup studentsGroup)
        {
            if (id != studentsGroup.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(studentsGroup);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentsGroupExists(studentsGroup.Id))
                    {
                        return(NotFound());
                    }
                    throw;
                }
                return(RedirectToAction("Index"));
            }
            ViewData["Specialty"] = new SelectList(_context.Specialty, "Id", "Name", studentsGroup.Specialty);
            return(View(studentsGroup));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName  = model.Email,
                    Email     = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    IsActive  = true
                };

                string roleId = _unitOfWork.AspNetRoleRepository.Get()
                                .Where(r => r.Name == "Candidate")                                //"Student")
                                .Select(r => r.Id)
                                .FirstOrDefault();
                user.RoleId = roleId;


                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Candidate");//"Student");

                    int groupId = _unitOfWork.GroupRepository.Get()
                                  .Where(g => (g.Specialization == model.Specialization) &&
                                         (g.Department == model.Department) &&
                                         (g.EnterYear == model.EnterYear))
                                  .Select(g => g.ID)
                                  .FirstOrDefault();

                    StudentsGroup sg = new StudentsGroup
                    {
                        Student_ID = user.Id,
                        Group_ID   = groupId
                    };

                    _unitOfWork.StudentsGroupRepository.Insert(sg);
                    _unitOfWork.Save();

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("SendEmail", "Account", new
                    {
                        fullName = string.Format("{0} {1}", user.FirstName, user.LastName),
                        email = user.Email
                    }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        private void ParseLine(StudentsGroup group, string line)
        {
            Examination exam = new Examination();

            exam.Deserialize(line);
            Add(group, exam);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            using (var db = new StudentsDB())
            {
                //db.Database.Log = str => Console.WriteLine("EF>> {0}", str);

                var students_count = db.Students.Count();

                Console.WriteLine("Students in DB: {0}", students_count);
            }

            using (var db = new StudentsDB())
                if (!db.Groups.Any())
                {
                    var student_n = 1;
                    for (var group_n = 1; group_n <= 10; group_n++)
                    {
                        var group = new StudentsGroup
                        {
                            Name = $"Group {group_n}"
                        };

                        for (var i = 0; i < 10; i++)
                        {
                            var student = new Student
                            {
                                Name       = $"Student {student_n}",
                                Surname    = $"Surname {student_n}",
                                Patronymic = $"Patronymic {student_n}",
                            };
                            group.Students.Add(student);
                            student_n++;

                            //db.Students.Add(student); // в этом нет необходимости!
                        }

                        db.Groups.Add(group);
                    }

                    db.Database.Log = str => Console.WriteLine("EF>> {0}", str);
                    db.SaveChanges();
                }


            using (var db = new StudentsDB())
            {
                db.Database.Log = str => Console.WriteLine("EF>> {0}", str);

                var students_group_id_7 = db.Students
                                          //.Include(student => student.Group)
                                          .Where(student => student.Group.Id == 7).ToArray();

                Console.ReadLine();

                Console.WriteLine(students_group_id_7[0].Group.Name);
            }

            Console.ReadLine();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            StudentsGroup StudentsGroup = db.StudentsGroups.Find(id);

            db.StudentsGroups.Remove(StudentsGroup);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public List <Student> GetAll()
        {
            var students = new List <Student>();

            try
            {
                _connection.Open();
                var cmd = new SqlCommand(
                    @"
                        SELECT 
                            [Groups].[Id],
                            [Groups].[Name],
                            [Groups].[Year],
                            [Students].[Id],
                            [Students].[FullName], 
                            [Students].[Gender], 
                            [Students].[Phone]
                        FROM
                            [Students]
                        LEFT JOIN
                            [Groups]
                        ON [Students].[GroupId] = [Groups].[Id]
                    ",
                    _connection
                    );

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var group = new StudentsGroup
                        {
                            Id           = reader.GetInt32(0),
                            Name         = reader.GetString(1),
                            YearCreation = reader.GetInt32(2),
                        };
                        var student = new Student
                        {
                            Id       = reader.GetInt32(3),
                            FullName = reader.GetString(4),
                            Gender   = reader.GetString(5),
                            Phone    = reader.GetString(6),
                            GroupId  = group.Id,
                            Group    = group
                        };

                        students.Add(student);
                    }
                }
            }
            finally
            {
                _connection.Close();
            }

            return(students);
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Level")] StudentsGroup StudentsGroup)
 {
     if (ModelState.IsValid)
     {
         db.Entry(StudentsGroup).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(StudentsGroup));
 }
Ejemplo n.º 8
0
        public List <StudentsGroup> GetAll()
        {
            var groups = new List <StudentsGroup>();

            try
            {
                _connection.Open();
                var cmd = new SqlCommand(
                    @"
                        SELECT 
                            [Specialties].[Id],
                            [Specialties].[Code], 
                            [Specialties].[Name],
                            [Groups].[Id],
                            [Groups].[Name],
                            [Groups].[Year]
                        FROM
                            [Groups]
                        LEFT JOIN
                            [Specialties]
                        ON [Groups].[SpecialtyId] = [Specialties].[Id]
                    ",
                    _connection
                    );

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var specialty = new Specialty
                        {
                            Id   = reader.GetInt32(0),
                            Code = reader.GetString(1),
                            Name = reader.GetString(2),
                        };
                        var group = new StudentsGroup
                        {
                            Id           = reader.GetInt32(3),
                            Name         = reader.GetString(4),
                            YearCreation = reader.GetInt32(5),
                            SpecialtyId  = specialty.Id,
                            Specialty    = specialty
                        };

                        groups.Add(group);
                    }
                }
            }
            finally
            {
                _connection.Close();
            }

            return(groups);
        }
        public ActionResult Create([Bind(Include = "Id,Name,Level")] StudentsGroup StudentsGroup)
        {
            if (ModelState.IsValid)
            {
                db.StudentsGroups.Add(StudentsGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(StudentsGroup));
        }
Ejemplo n.º 10
0
        public void VerifyIfAddStudentInGroup()
        {
            var student1  = new Student(new Name("Lazaro", "Campos"), 21660411, "*****@*****.**");
            var student2  = new Student(new Name("Test", "Testou"), 66608121, "*****@*****.**");
            var workGroup = new StudentsGroup("groupA", 1);

            workGroup.AddStudent(student1);
            var res = workGroup.AddStudent(student2);

            Assert.True(res == "Grupo já atingiu o limite de estudantes!");
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create(
            [Bind("Id,Name,DateStart,DateFinish,Specialty,Course")] StudentsGroup studentsGroup)
        {
            if (ModelState.IsValid)
            {
                _context.Add(studentsGroup);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["Specialty"] = new SelectList(_context.Specialty, "Id", "Name", studentsGroup.Specialty);
            return(View(studentsGroup));
        }
        // GET: StudentsGroups/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentsGroup StudentsGroup = db.StudentsGroups.Find(id);

            if (StudentsGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(StudentsGroup));
        }
Ejemplo n.º 13
0
        public void ChangeItemHandler(StudentsGroup item)
        {
            var editor = new GroupEditorForm();

            var result = editor.ShowDialog(item, _context.Specialties.GetAll());

            if (result != DialogResult.OK)
            {
                return;
            }

            _context.Groups.Update(editor.ChangedItem);
            RefreshDataHandler();
        }
Ejemplo n.º 14
0
        public DialogResult ShowDialog(StudentsGroup item, List <Specialty> specialties)
        {
            if (item == null)
            {
                item = new StudentsGroup();
            }

            Id                        = item.Id;
            nameBox.Text              = item.Name;
            yearTextBox.Text          = item.YearCreation.ToString();
            specialtyBox.DataSource   = specialties;
            specialtyBox.SelectedItem = specialtyBox.Items.IndexOf(item.Specialty);

            return(ShowDialog());
        }
        public void UpdateGroup(StudentsGroup group) // TODO
        {
            var x = group;

            if (group.StudentsGroupId == 0)
            {
                _context.Add(group);
                // create new
            }
            else
            {
                // update existing
                ;
            }
            _context.SaveChanges();
        }
Ejemplo n.º 16
0
        public bool Add(StudentsGroup data)
        {
            var cmd = new SqlCommand(
                @"
                        INSERT INTO [Groups]
                            ([Name], [Year], [SpecialtyId])
                        VALUES
                            (@Name, @Year, @SpecialtyId)
                    ",
                _connection
                );

            cmd.Parameters.AddWithValue("@Name", data.Name);
            cmd.Parameters.AddWithValue("@Year", data.YearCreation);
            cmd.Parameters.AddWithValue("@SpecialtyId", data.SpecialtyId);

            return(MyExecuteNonQuery(cmd));
        }
Ejemplo n.º 17
0
        public bool Update(StudentsGroup data)
        {
            var cmd = new SqlCommand(
                @"
                    UPDATE [Groups]
                    SET
                        [Name] = @Name,
                        [Year] = @Year,
                        [SpecialtyId] = @SpecialtyId
                    WHERE
                        [Id] = @Id
                ",
                _connection
                );

            cmd.Parameters.AddWithValue("@Id", data.Id);
            cmd.Parameters.AddWithValue("@Name", data.Name);
            cmd.Parameters.AddWithValue("@Year", data.YearCreation);
            cmd.Parameters.AddWithValue("@SpecialtyId", data.Specialty.Id);

            return(MyExecuteNonQuery(cmd));
        }
        public ActionResult Details(int?studentGroupId, int?subjectId)
        {
            if (studentGroupId == null || studentGroupId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (User.IsInRole("Teacher"))
            {
                var studentsGroup = db.StudentsGroups.FirstOrDefault(x => x.Id == studentGroupId);
                var subjectName   = db.Subjects.FirstOrDefault(x => x.Id == subjectId).Name;

                var myUsers = db.MyUsers.Where(x => x.StudentsGroupId == studentGroupId).Select(x => new StudentGroupViewModel()
                {
                    MyUser           = x,
                    SubjectName      = subjectName,
                    StudentGroupName = studentsGroup.Level + studentsGroup.Name,
                    StudentGroupId   = (int)studentGroupId,
                    SubjectId        = (int)subjectId
                }).ToList();


                foreach (var myUser in myUsers)
                {
                    myUser.Grades = db.Grades.Where(x => x.Owner == myUser.MyUser.Owner && x.SubjectId == subjectId).ToList();
                }

                return(View("~\\Views\\StudentsGroups\\DetailsTeacher.cshtml", myUsers));
            }

            StudentsGroup StudentsGroup = db.StudentsGroups.Find(studentGroupId);

            if (StudentsGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(StudentsGroup));
        }
 public List <Examination> GetGroup(StudentsGroup group)
 {
     return(_set[group]);
 }
Ejemplo n.º 20
0
 public bool Update(int id, StudentsGroup data)
 {
     return(true);
 }
 private void Add(StudentsGroup group, Examination exam)
 {
     GetGroup(group).Add(exam);
 }
Ejemplo n.º 22
0
 public bool Add(StudentsGroup data)
 {
     return(true);
 }