Beispiel #1
0
        public bool RegisterNewUser(RegisterViewModel model)
        {
            var user = new ApplicationUser {
                UserName = model.Email, Email = model.Email
            };
            var result = UserManager.Create(user, model.Password);

            if (result.Succeeded)
            {
                var context = new UnitOfWork(new KhMediumEntities());
                var author  = new Author();
                author.Id             = Guid.NewGuid().ToString();
                author.Name           = model.Name;
                author.Bio            = model.Bio;
                author.CreatedAt      = DateTime.Now;
                author.UpdatedAt      = DateTime.Now;
                author.UserId         = user.Id;
                author.ProfilePicture = model.Profile == null
                    ? "default.png"
                    : FileController.SaveFile(model.Profile).Path;
                context.Authors.Add(author);
                context.Complete();

                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                return(true);
            }
            return(false);
        }
        public ActionResult Create(CreatePublicationViewModel model)
        {
            var publication = new Publication();

            publication.Id          = Guid.NewGuid().ToString();
            publication.Name        = model.Name;
            publication.Description = model.Description;
            publication.Logo        = FileController.SaveFile(model.Logo).Path;
            publication.Cover       = FileController.SaveFile(model.Cover).Path;
            publication.CreatedAt   = DateTime.Now;
            publication.UpdatedAt   = DateTime.Now;
            _context.Publications.Add(publication);
            _context.Complete();

            var author    = _context.Authors.GetAuthorByUserId(User.Identity.GetUserId());
            var authorPub = new AuthorPublication();

            authorPub.Id            = Guid.NewGuid().ToString();
            authorPub.PublicationId = publication.Id;
            authorPub.AuthorId      = author?.Id;
            _context.AuthorPublication.Add(authorPub);

            _context.Complete();
            return(View());
        }
Beispiel #3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var context = new UnitOfWork(new KhMediumEntities());
                    var author  = new Author();
                    author.Id             = Guid.NewGuid().ToString();
                    author.Name           = model.Name;
                    author.Bio            = model.Bio;
                    author.CreatedAt      = DateTime.Now;
                    author.UpdatedAt      = DateTime.Now;
                    author.UserId         = user.Id;
                    author.ProfilePicture = model.Profile == null
                        ? "default.png"
                        : FileController.SaveFile(model.Profile).Path;
                    context.Authors.Add(author);
                    context.Complete();
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("SelectTopics", "Start"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #4
0
        public ActionResult CreateArticlesDemo(CreateArticleViewModel model, HttpPostedFileBase ArticlesImage)
        {
            var file = Request.Files[0];
            //Foreign Keys are simulated for simplicity
            var article = new Article();

            article.Id        = Guid.NewGuid().ToString();
            article.Title     = model.Title;
            article.TopicId   = "6b92ef38-f1b0-4911-8199-eeeadeb25bef";
            article.Content   = model.Content;
            article.AuthorId  = "wwe";
            article.CreatedAt = DateTime.Now;
            article.UpdatedAt = DateTime.Now;

            var thumnail = FileController.SaveFile(model.ArticlesImage);

            article.Thumbnail = thumnail.FullPath();
            _context.Articles.Add(article);
            _context.Complete();

            return(View());
        }
        public ActionResult CreateArticle(CreateArticleViewModel model)
        {
            var file = Request.Files[0];
            //Foreign Keys are simulated for simplicity
            var article = new Article();

            article.Id      = Guid.NewGuid().ToString();
            article.Title   = model.Title;
            article.TopicId = model.TopicId;
            article.Content = model.Content;
            Console.WriteLine(User.Identity.GetUserId());
            article.AuthorId  = _context.Authors.GetAuthorByUserId(User.Identity.GetUserId()).Id;
            article.CreatedAt = DateTime.Now;
            article.UpdatedAt = DateTime.Now;

            var thumbnail = FileController.SaveFile(model.ArticlesImage);

            article.Thumbnail = thumbnail.Path;
            _context.Articles.Add(article);
            _context.Complete();

            return(View("Index"));
        }