Exemple #1
0
        public AuthResponse RegisterUndergraduate(UndergraduateRegisterVM undergraduate)
        {
            var dbUser  = this._repository.Users.FindByLoginPassword(undergraduate.User.Login.Login, undergraduate.User.Login.Password);
            var context = new AuthResponse();

            if (dbUser == null)
            {
                var entity = this._mapper.Map <Undergraduate>(undergraduate);

                var thesisData = new ThesisCertification()
                {
                    Protocol = new Protocol()
                };
                var journal = new UndergraduateJournal()
                {
                    ThesisCertification = thesisData
                };

                entity.Journals.Add(journal);
                entity.User.RoleId = this.GetOrAddRole(RoleNames.Undergraduate);

                this._repository.Undergraduates.Add(entity);
                this._repository.Save();

                context.User                 = this._mapper.Map <UserContext>(entity.User);
                context.User.Role            = RoleNames.Undergraduate;
                context.User.SpecifiedUserId = entity.UndergraduateId;

                return(context);
            }

            context.Alert = Config.LoginExist;
            return(context);
        }
Exemple #2
0
        public IActionResult RegisterUndergraduate([FromBody] UndergraduateRegisterVM undergraduate)
        {
            if (undergraduate is null)
            {
                return(Ok(new { Alert = Config.BadRequest }));
            }

            var authContext = this._userManager.RegisterUndergraduate(undergraduate);

            if (authContext.User != null)
            {
                authContext.Token = this._tokenProvider.GenerateToken(authContext.User.Login, authContext.User.Role);
                return(Ok(authContext));
            }

            return(Ok(authContext));
        }