Beispiel #1
0
        public void RegisterCurator_RequestCurator_ReturnOkObjectResultAndSuccessfullyAddedToDb()
        {
            var user = new User
            {
                FirstName = "Алекс",
                SurName   = "Баранов",
                Login     = "******",
                Password  = "******",
                Role      = new Role {
                    Name = "Куратор"
                },
            };

            var curator = new Curator
            {
                CuratedGroups = "41 42",
                Faculty       = new Faculty {
                    Name = "ИВТФ и ЭМФ"
                },
                User = user,
            };

            CuratorViewModel viewModel = new CuratorViewModel(curator);

            UserRepository  repository = new UserRepository(fixture.Context);
            UsersController controller = new UsersController(repository);
            var             oldLenght  = fixture.Context.Curators.ToList().Count;

            var result    = controller.RegisterCurator(viewModel);
            var newLength = fixture.Context.Curators.ToList().Count;

            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(oldLenght + 1, newLength);
        }
Beispiel #2
0
        public int?RegisterCurator(CuratorViewModel curatorViewModel)
        {
            if (curatorViewModel != null)
            {
                string curatedGroups = curatorViewModel.CuratedGroups;
                //ParseCuratedGroups(curatorViewModel.CuratedGroups, out curatedGroups);


                Curator curator = new Curator()
                {
                    User = new User()
                    {
                        Login     = curatorViewModel.User.Login,
                        Password  = curatorViewModel.User.Password,
                        FirstName = curatorViewModel.User.FirstName,
                        SurName   = curatorViewModel.User.SurName,
                        Role      = context.Roles.SingleOrDefault(r => r.Name == curatorViewModel.User.Role.Name),
                    },
                    Faculty       = context.Faculties.SingleOrDefault(f => f.Id == curatorViewModel.Faculty.Id),
                    CuratedGroups = curatedGroups,
                };

                context.Curators.Add(curator);
                context.SaveChanges();

                return(1);
            }
            return(null);
        }
Beispiel #3
0
        public IActionResult GetCurator(int userId)
        {
            CuratorViewModel viewModel = repository.GetCurator(userId);

            if (viewModel != null)
            {
                return(Ok(viewModel));
            }
            return(NotFound("Куратор с таким Id не существует!"));
        }
Beispiel #4
0
        public IActionResult RegisterCurator([FromBody] CuratorViewModel curatorViewModel)
        {
            int?result = repository.RegisterCurator(curatorViewModel);

            if (result != null)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest("Error!"));
            }
        }
Beispiel #5
0
        public void RegisterCurator_RequestBadData_ReturnBadRequest()
        {
            CuratorViewModel viewModel = null;

            UserRepository  repository = new UserRepository(fixture.Context);
            int             oldLenght  = fixture.Context.Curators.ToList().Count;
            UsersController controller = new UsersController(repository);

            var result    = controller.RegisterCurator(viewModel);
            int newLength = fixture.Context.Curators.ToList().Count;

            Assert.IsType <BadRequestObjectResult>(result);
            Assert.Equal(oldLenght, newLength);
        }
Beispiel #6
0
        public PartialViewResult CreateCurator(CuratorViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    WebSecurity.CreateUserAndAccount(model.Email, model.Password,
                                                     new
                    {
                        WorkPlace     = model.WorkPlace,
                        Chair         = model.Chair,
                        Post          = model.Post,
                        AcademicTitle = model.AcademicTitle,
                        Degree        = model.Degree,
                        CreatedAt     = DateTime.Now,
                        UpdatedAt     = DateTime.Now,
                        IsActive      = true
                    },
                                                     false);
                    Roles.AddUserToRole(model.Email, Constants.ROLES_LIST[(int)Constants.Roles.CURATOR]);

                    ModelState.Clear();
                    ViewBag.IsCuratorCreated = true;
                    return(PartialView("_CreateCurator"));
                }
                catch (InvalidOperationException e)
                {
                    ModelState.AddModelError("", e.Message);
                }
                catch (ArgumentNullException e)
                {
                    ModelState.AddModelError("", e.Message);
                }
                catch (ArgumentException e)
                {
                    ModelState.AddModelError("", e.Message);
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }
            return(PartialView("_CreateCurator", model));
        }
        public async Task <HttpResponseMessage> EditCurator(Guid curatorId, [FromBody] CuratorViewModel curator)
        {
            await _curatorService.UpdateAsync(curatorId, Mapper.Map <CuratorDto>(curator));

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public async Task <HttpResponseMessage> CreateCurator([FromBody] CuratorViewModel curator)
        {
            await _curatorService.AddAsync(Mapper.Map <CuratorDto>(curator));

            return(Request.CreateResponse(HttpStatusCode.OK));
        }