コード例 #1
0
 public Group Map(GroupPostModel entity)
 {
     return(new Group
     {
         GroupId = entity.GroupId,
         GroupName = entity.GroupName,
         Speciality = new Speciality {
             SpecialityId = entity.SpecialityId
         }
     });
 }
コード例 #2
0
        public async Task <IActionResult> AddOrUpdateGroup(
            [FromBody] GroupPostModel groupPostModel,
            [FromQuery] bool add = true)
        {
            var group = _groupMapper.Map(groupPostModel);

            if (add)
            {
                await _groupService.AddAsync(group);
            }
            else
            {
                await _groupService.UpdateAsync(group);
            }

            await _groupService.SetStudentsFromGroup(group.GroupId, (IReadOnlyCollection <int>) groupPostModel.Students);

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <ActionResult> AddOrUpdateGroup([FromQuery] bool add, [FromQuery] int?groupId)
        {
            var students = await _studentService.GetAll();

            var selectStudents = _studentSelectModelMapper.Map(students).ToList();

            await _viewBagDataProvider.InitFacultiesAndSpecialities(ViewBag);

            GroupPostModel model;

            if (add)
            {
                model = new GroupPostModel();

                ViewBag.Header = ControllerConstants.AddGroupHeader;
            }
            else
            {
                var group = await _groupService.GetById(groupId.GetValueOrDefault());

                model = _groupPostModelMapper.Map(group);

                foreach (var student in selectStudents)
                {
                    if (model.Students.Contains(student.StudentId))
                    {
                        student.Checked = true;
                    }
                }

                ViewBag.Header = ControllerConstants.UpdateGroupHeader;
            }

            ViewBag.Students = selectStudents;
            ViewBag.ReadOnlySelectStudents = false;

            return(View(model));
        }