Esempio n. 1
0
        public async Task MakeAsync(ReplyInputModel model, GamingForumUser Replier)
        {
            Reply reply = this.mapper.Map <ReplyInputModel, Reply>(model);

            reply.Replier   = Replier;
            reply.RepliedOn = DateTime.UtcNow;

            await this.context.Replies.AddAsync(reply);

            await this.context.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task CreateAsync(PostInputModel model, GamingForumUser poster)
        {
            Post post = this.mapper.Map <PostInputModel, Post>(model);

            post.Poster   = poster;
            post.PostedOn = DateTime.UtcNow;

            await this.context.Posts.AddAsync(post);

            await this.context.SaveChangesAsync();
        }
Esempio n. 3
0
        public async Task CreateAsync(CategoryInputModel model, GamingForumUser creator)
        {
            Category category = this.mapper.Map <CategoryInputModel, Category>(model);

            category.Creator   = creator;
            category.CreatedOn = DateTime.UtcNow;

            await this.context.Categories.AddAsync(category);

            await this.context.SaveChangesAsync();
        }
Esempio n. 4
0
        public async Task <IActionResult> Make(ReplyInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                GamingForumUser replier = await this.accountService.GetLoggedInUserAsync(this.User);

                await this.replyService.MakeAsync(model, replier);

                return(this.Redirect($"/Post/Details/{model.PostId}"));
            }
            else
            {
                ViewResult result = this.View("Error", this.ModelState);

                result.StatusCode = (int)HttpStatusCode.BadRequest;

                return(result);
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Create(PostInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                GamingForumUser poster = await this.accountService.GetLoggedInUserAsync(this.User);

                await this.postService.CreateAsync(model, poster);

                return(this.Redirect($"/Category/Details/{model.CategoryId}"));
            }
            else
            {
                ViewResult result = this.View("Error", this.ModelState);

                result.StatusCode = (int)HttpStatusCode.BadRequest;

                return(result);
            }
        }
Esempio n. 6
0
        public async Task <IActionResult> Create(CategoryInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                GamingForumUser creator = await this.accountService.GetLoggedInUserAsync(this.User);

                await this.categoryService.CreateAsync(model, creator);

                return(this.RedirectToAction(nameof(All)));
            }
            else
            {
                ViewResult result = this.View("Error", this.ModelState);

                result.StatusCode = (int)HttpStatusCode.BadRequest;

                return(result);
            }
        }
Esempio n. 7
0
        private async Task <IdentityResult> RegisterAsync(GamingForumUser user, string password)
        {
            IdentityResult result = await this.userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                if (this.context.Users.Count() == 1)
                {
                    await this.userManager.AddToRoleAsync(user, Role.Administrator.ToString());
                }
                else
                {
                    await this.userManager.AddToRoleAsync(user, Role.User.ToString());
                }

                await this.signInManager.SignInAsync(user, isPersistent : false);
            }

            return(result);
        }
Esempio n. 8
0
 private async Task <SignInResult> LogInAsync(GamingForumUser user, string password)
 => await this.signInManager.PasswordSignInAsync(user.UserName, password, false, lockoutOnFailure : true);
Esempio n. 9
0
        public async Task RegisterAsync(RegisterInputModel model)
        {
            GamingForumUser user = this.mapper.Map <RegisterInputModel, GamingForumUser>(model);

            await this.RegisterAsync(user, model.Password);
        }
Esempio n. 10
0
        public async Task LogInAsync(LoginInputModel model)
        {
            GamingForumUser user = this.mapper.Map <LoginInputModel, GamingForumUser>(model);

            await this.LogInAsync(user, model.Password);
        }