示例#1
0
        public IActionResult OnPost()
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            Books.Models.Author author = this.Context.Authors.Where(a => a.Name == this.Author).FirstOrDefault();
            if (author == null)
            {
                author = new Books.Models.Author()
                {
                    Name = this.Author
                };
                this.Context.Authors.Add(author);
                this.Context.SaveChanges();
            }

            var status = new Status()
            {
                IsAvailable = true
            };

            Books.Models.Book book = new Books.Models.Book()
            {
                Title          = this.Title,
                Description    = this.Description,
                BookCoverImage = this.ImageUrl,
                AuthorId       = author.Id,
                Status         = status
            };
            this.Context.Books.Add(book);
            this.Context.SaveChanges();

            return(this.RedirectToPage("/Book/Details", new { id = book.Id }));
        }
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var info = await Authentication.GetExternalLoginInfoAsync();
            if (info == null)
            {
                return InternalServerError();
            }

            var user = new Author() { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result); 
            }
            return Ok();
        }
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new Author() { UserName = model.Email, Email = model.Email };

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

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok();
        }