public ActionResult Create(ArticleCreateViewModel form, int SubcategoryId, int CategoryId, string ArticleContents)
        {
            Models.User user    = this.Session["User"] as Models.User;
            Article     article = new Article();

            article.UserId             = user.UserId;
            article.ArticleName        = form.article.ArticleName;
            article.ArticleDescription = form.article.ArticleDescription;
            article.CategoryId         = CategoryId;
            article.SubcategoryId      = SubcategoryId;
            article.ArticleCreated     = form.article.ArticleCreated;
            article.ArticleContents    = ArticleContents;


            if (ModelState.IsValid)
            {
                db.Articles.Add(article);
                db.SaveChanges();
                return(RedirectToAction("Details", "Articles", new { id = article.ArticleId }));
                //return RedirectToAction("Index", "Home");
            }

            ViewBag.CategoryId    = new SelectList(db.Categories, "CategoryId", "CategoryName", article.CategoryId);
            ViewBag.SubcategoryId = new SelectList(db.Subcategories, "SubcategoryId", "SubcategoryName", article.SubcategoryId);
            return(View(article));
        }
        // GET: Article/Delete/5
        public ActionResult Delete(int id)
        {
            var viewModel = new ArticleCreateViewModel {
                Article = _articleRepository.Get(id), ArticleCategories = _articleCategoryRepository.GetAll(), ArticlePhoto = _articlePhotoRepository.GetByArticleId(id)
            };

            return(View(viewModel));
        }
        // GET: Article/Create
        public ActionResult Create()
        {
            var viewModel = new ArticleCreateViewModel {
                Article = new ArticleModel(), ArticleCategories = _articleCategoryRepository.GetAll()
            };

            return(View(viewModel));
        }
Exemple #4
0
        public ActionResult Create()
        {
            ArticleCreateViewModel model = new ArticleCreateViewModel();

            model.Privacy     = MainPostPrivacyEnum.Everyone;
            ViewBag.System    = Constant.String.BlogSystem;
            ViewBag.ReturnUrl = _previousUrl == default(string) ? Url.Action("Index") : Url.Content(_previousUrl);
            return(View("Views/BlogCreateView", model));
        }
Exemple #5
0
        public async Task <IActionResult> Create(ArticleCreateViewModel newArticleInfo)
        {
            if (ModelState.IsValid)
            {
                var checkAffiliation = (from af in _context.Affiliations
                                        where af.Name.ToLower() == newArticleInfo.Affiliation.Name.ToLower()
                                        select af).SingleOrDefault();

                var checkAuthor = (from au in _context.Authors
                                   where au.FirstName.ToLower() == newArticleInfo.Author.FirstName.ToLower() &&
                                   au.LastName.ToLower() == newArticleInfo.Author.LastName.ToLower()
                                   select au).SingleOrDefault();

                if (checkAffiliation == null)
                {
                    Affiliation newAffiliation = new Affiliation()
                    {
                        Name = newArticleInfo.Affiliation.Name
                    };

                    _context.Affiliations.Add(newAffiliation);
                    await _context.SaveChangesAsync();

                    newArticleInfo.Article.AffiliationId = newAffiliation.Id;
                }
                else
                {
                    newArticleInfo.Article.AffiliationId = checkAffiliation.Id;
                }

                if (checkAuthor == null)
                {
                    Author newAuthor = new Author()
                    {
                        FirstName = newArticleInfo.Author.FirstName,
                        LastName  = newArticleInfo.Author.LastName,
                        HIndex    = newArticleInfo.Author.HIndex
                    };

                    _context.Authors.Add(newAuthor);
                    await _context.SaveChangesAsync();

                    newArticleInfo.Article.AuthorId = newAuthor.Id;
                }
                else
                {
                    newArticleInfo.Article.AuthorId = checkAuthor.Id;
                }

                _context.Articles.Add(newArticleInfo.Article);
                await _context.SaveChangesAsync();

                return(RedirectToAction("MainPage", "Home"));
            }
            return(View());
        }
Exemple #6
0
        public async Task <IActionResult> Add(ArticleCreateViewModel model)
        {
            var userId = this.userManager.GetUserId(User);

            await this.articles.CreateAsync(userId, model.Title, model.Content);

            TempData.AddSuccessMessage($"Article created successfully!");

            return(RedirectToAction(nameof(All)));
        }
        public ActionResult Create(ArticleCreateViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                model.Author = User.Identity.Name;
                this.ArticleService.Create(model, User.Identity.Name);
                return this.View(model);
            }

            return this.View(model);
        }
Exemple #8
0
        public ViewResult Create(int boardId)
        {
            var model = new ArticleCreateViewModel {
                Article = new PostArticleModel()
                {
                    BoardId = boardId
                }
            };

            return(View(model));
        }
Exemple #9
0
 public ArticleModel(ArticleCreateViewModel article, ApplicationUser user, string path)
 {
     Name              = article.Name;
     Description       = article.Description;
     Theme             = article.Theme;
     ApplicationUser   = user;
     ImagePath         = path;
     Date              = DateTime.Now;
     Steps             = new List <StepModel>();
     Comments          = new List <CommentModel>();
     ArticleUserRating = new List <Data.ArticleUserRating>();
 }
Exemple #10
0
        public async Task <ActionResult> Create([FromForm] ArticleCreateViewModel article)
        {
            try
            {
                await _articlesApiProxy.CreateAsync <ArticleCreateViewModel>(article, _tokenAuth.GetToken());

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                return(View(article));
            }
        }
        public async Task <IActionResult> CreateArticle(ArticleCreateViewModel article)
        {
            var path = await UploadFile(article.ImagePath);

            var currentUser = await GetUser();

            var tags = FindTag(article.Tags.Split(' '));
            var res  = _db.Articles.Add(new ArticleModel(article, currentUser, path));

            _db.SaveChanges();
            CreateTagArticle(res.Entity, tags);
            ViewBag.List = Theme.ListOfTheme;
            return(View("UpdateArticle", res.Entity));
        }
 // GET: Articles/Create
 public ActionResult Create()
 {
     if (this.Session["User"] == null)
     {
         return(RedirectToAction("Login", "Users"));
     }
     else
     {
         ViewBag.CategoryId = new SelectList(db.Categories.Where(a => a.CategoryId != 1), "CategoryId", "CategoryName");
         ArticleCreateViewModel viewModel = new ArticleCreateViewModel();
         viewModel.subcategories = new List <ArticleSubcategory>();
         return(View(viewModel));
     }
 }
Exemple #13
0
        public async Task <IActionResult> Create(ArticleCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = _userManager.GetUserId(User);

                var article = new Article();

                article.Title   = model.Title;
                article.Content = model.Content;
                article.Tags    = new List <ArticleTag>();

                // Add tags
                if (!string.IsNullOrEmpty(model.Tags))
                {
                    var tags = model.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries);

                    if (tags.Any())
                    {
                        foreach (var tag in tags)
                        {
                            var dbTag = _context.Tags.FirstOrDefault(t => t.Name.ToLower() == tag.ToLower());
                            if (dbTag == null)
                            {
                                // Tag does not exist, create it
                                dbTag      = new Tag();
                                dbTag.Name = tag;
                                _context.Tags.Add(dbTag);
                            }

                            var articleTag = new ArticleTag();
                            articleTag.Article = article;
                            articleTag.Tag     = dbTag;

                            article.Tags.Add(articleTag);
                        }
                    }
                }

                article.AuthorId        = userId;
                article.PublicationDate = DateTime.Now;


                _context.Add(article);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public ActionResult Create(ArticleCreateViewModel article)
        {
            if (ModelState.IsValid)
            {
                Article articleEntity = article.TransformToArticle();
                FileHelper.SaveImage(articleEntity, article.Image);
                Data.Articles.Add(articleEntity);
                Data.SaveChanges();

                return(RedirectToAction("Details", new { id = articleEntity.Id, returnUrl = article.ReturnUrl })
                       .WithSuccess(string.Format(_msg, article.NameEn, "created")));
            }

            return(View(article));
        }
Exemple #15
0
        public void Create(ArticleCreateViewModel articleData, string userId)
        {
            var article = new Article()
            {
                ID          = Guid.NewGuid().ToString(),
                Subject     = articleData.Subject,
                Summary     = articleData.Summary,
                ContentText = Sanitizer.GetSafeHtmlFragment(articleData.ContentText),
                ViewCount   = 0,
                CreateUser  = userId,
                CreateDate  = DateTime.Now,
                UpdateUser  = userId,
                UpdateDate  = DateTime.Now
            };

            _articleRep.Create(article);
        }
Exemple #16
0
        public void Update(ArticleCreateViewModel viewModel)
        {
            var result = _context.Articles.SingleOrDefault(x => x.ArticleId == viewModel.Article.ArticleId);

            if (result != null)
            {
                result.CategoryId    = viewModel.Article.CategoryId;
                result.DateOfPublish = viewModel.Article.DateOfPublish;
                result.Text          = viewModel.Article.Text;
                result.Title         = viewModel.Article.Title;
                _context.SaveChanges();
            }
            if (viewModel.ArticlePhoto != null)
            {
                var resultPhoto = _context.ArticlePhotos.SingleOrDefault(x => x.ArticleId == viewModel.Article.ArticleId);
                if (resultPhoto != null)
                {
                    //delete ArticlePhoto from /images/Articles
                    var imagePath = Path.Combine(_webHostEnvironment.WebRootPath, "images/Articles", resultPhoto.FileName);
                    if (System.IO.File.Exists(imagePath))
                    {
                        System.IO.File.Delete(imagePath);
                    }
                    //delete ArticlePhoto from DB
                    _context.ArticlePhotos.Remove(resultPhoto);
                    _context.SaveChanges();

                    viewModel.ArticlePhoto.ArticleId = viewModel.Article.ArticleId;
                    viewModel.ArticlePhoto.FileName  = viewModel.ArticlePhoto.PhotoFile.FileName;

                    //Save ArticlePhoto to /images/Articles/
                    string wwwRootPath   = _webHostEnvironment.WebRootPath;
                    string fileName      = Path.GetFileNameWithoutExtension(viewModel.ArticlePhoto.FileName);
                    string fileExtension = Path.GetExtension(viewModel.ArticlePhoto.FileName);
                    viewModel.ArticlePhoto.FileName = fileName = fileName + DateTime.Now.ToString("yymmssffff") + fileExtension;
                    string filePath = Path.Combine(wwwRootPath + "/images/Articles", fileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        viewModel.ArticlePhoto.PhotoFile.CopyTo(fileStream);
                    }
                    //Insert ArticlePhoto into DB
                    _context.Add(viewModel.ArticlePhoto);
                    _context.SaveChanges();
                }
            }
        }
        public ActionResult Create()
        {
            DataServiceMessage <IEnumerable <string> > serviceMessage = categoryService.GetAllNames();

            if (serviceMessage.Succeeded)
            {
                var categoryNames            = GetAllCategoryNames();
                ArticleCreateViewModel model = new ArticleCreateViewModel
                {
                    Categories = ConvertToSelectListItems(categoryNames)
                };

                return(ActionResultDependingOnGetRequest(model));
            }
            else
            {
                return(Error(serviceMessage.Errors));
            }
        }
Exemple #18
0
        public async Task <ActionResult> Create(ArticleCreateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = await UserManager.FindByNameAsync(User.Identity.GetUserName());

                    _articleSvc.Create(model, user.Id);
                    _articleSvc.Save();
                    return(RedirectToAction("Index"));
                }
                return(View());
            }
            catch
            {
                return(View());
            }
        }
Exemple #19
0
        public void Add(ArticleCreateViewModel viewModel)
        {
            viewModel.ArticlePhoto.ArticleId = viewModel.Article.ArticleId;
            viewModel.ArticlePhoto.FileName  = viewModel.ArticlePhoto.PhotoFile.FileName;

            //Save ArticlePhoto to /images/Articles/
            string wwwRootPath   = _webHostEnvironment.WebRootPath;
            string fileName      = Path.GetFileNameWithoutExtension(viewModel.ArticlePhoto.FileName);
            string fileExtension = Path.GetExtension(viewModel.ArticlePhoto.FileName);

            viewModel.ArticlePhoto.FileName = fileName = fileName + DateTime.Now.ToString("yymmssffff") + fileExtension;
            string filePath = Path.Combine(wwwRootPath + "/images/Articles", fileName);

            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                viewModel.ArticlePhoto.PhotoFile.CopyTo(fileStream);
            }

            //Insert ArticlePhoto into DB
            _context.Add(viewModel.ArticlePhoto);
            _context.SaveChanges();
        }
Exemple #20
0
        // GET: Article/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            ArticleCreateViewModel articleEditModel = null;

            try
            {
                var article = await _articlesApiProxy.FindAsync <ArticleDetailsViewModel>(id);

                articleEditModel = new ArticleCreateViewModel()
                {
                    Content = article.Content,
                    Title   = article.Title,
                    Tags    = "#" + string.Join('#', article.Tags)
                };
            }
            catch (Exception)
            {
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.Title = articleEditModel?.Title;

            return(View(articleEditModel));
        }
Exemple #21
0
        public async Task <ActionResult> Create(ArticleCreateViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            // Create the article
            GetArticleModel model = await Mediator.Send(new AddArticleCommand(viewModel.Article));

            // If image attatched
            var file = Request.Form.Files.FirstOrDefault();

            if (file != null)
            {
                PostImageModel imageModel = _imageFileReader.ConvertImageFileToImageModel(file);

                // Add the image to the article
                await Mediator.Send(new AddArticleImageCommand(imageModel, model.Id));
            }

            return(RedirectToAction("Details", new { model.Id }));
        }
        public ActionResult Create(ArticleCreateViewModel model)
        {
            var categoryNames = GetAllCategoryNames();

            model.Categories = ConvertToSelectListItems(categoryNames);
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string fileName   = String.Format("{0}_{1}{2}", model.CategoryName, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), System.IO.Path.GetExtension(model.Photo.FileName));
            string serverPath = Server.MapPath("~/Images/Uploads");
            string path       = System.IO.Path.Combine(serverPath, fileName);

            ArticleCreateDTO articleDTO = Mapper.Map <ArticleCreateViewModel, ArticleCreateDTO>(model);

            articleDTO.PhotoLink = path;

            ServiceMessage serviceMessage = articleService.Create(articleDTO);

            if (serviceMessage.Succeeded)
            {
                model.Photo.SaveAs(path);
            }
            else
            {
                AddModelErrors(serviceMessage.Errors);
                return(View(model));
            }

            ModelState.Clear();
            return(View(new ArticleCreateViewModel
            {
                Categories = ConvertToSelectListItems(categoryNames)
            }));
        }
 public ActionResult Create(ArticleCreateViewModel viewModel)
 {
     _articleRepository.Add(viewModel.Article);
     _articlePhotoRepository.Add(viewModel);
     return(RedirectToAction(nameof(Index)));
 }
Exemple #24
0
        public ActionResult Create(ArticleCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Views/BlogCreateView", model));
            }
            Article article = new Article();

            article             = Mapper.Map <ArticleCreateViewModel, Article>(model);
            article.UserId      = User.Identity.GetUserId <int>();
            article.Tags        = cService.GetTags(model.TagIds);
            article.Invitations = cService.GetInvitations(model.InviteIds, User.Identity.GetUserId <int>());
            if (article.PublicDate.Value.Date == DateTime.Now.Date)
            {
                article.PublicDate = DateTime.Now;
            }

            bService.InsertArticle(article);

            EditedLog editedlog = new EditedLog();

            editedlog.Content     = article.Content;
            editedlog.CreatedDate = article.LastEditedDate;
            editedlog.PostId      = article.Id;
            editedlog.UserId      = article.UserId;
            editedlog.Title       = article.Title;
            article.EditedContents.Add(editedlog);

            bService.UpdateArticle(article);
            //Console.WriteLine(questionVM.Tags[0]);
            if (article.Id != 0)
            {
                //new Thread(() =>
                //{
                foreach (int inviteeId in article.Invitations.Select(i => i.InviteeId))
                {
                    Notification notification = new Notification();
                    notification.AuthorId    = _currentUserId;
                    notification.CreatedDate = DateTime.Now;
                    notification.Content     = article.Title;
                    notification.Seen        = false;
                    notification.Type        = NotificationSettingEnum.Invited;
                    notification.UserId      = inviteeId;
                    notification.Link        = Url.Action("Detail", "Article", new { id = article.Id });
                    cService.AddNotification(notification);
                    using (RealTimeService rService = new RealTimeService(new CPMathHubModelContainer(), notification.UserId))
                    {
                        IEnumerable <string> connectionIds = RealTimeHub.Connections.GetConnections(notification.UserId);
                        foreach (string conId in connectionIds)
                        {
                            _hub.Clients.Client(conId).notifyNewActivity(rService.CountNewActivityNotification());
                        }
                    }
                }
                //    }
                //).Start();
                return(RedirectToAction("Detail", new { id = article.Id }));
            }
            else
            {
                return(new HttpStatusCodeResult(500));
            }
        }
 public ActionResult Create()
 {
     var model = new ArticleCreateViewModel();
     model.ChosenCategories = this.CategoryService.GetAllCheckbox().ToList();
     return this.View(model);
 }
 public ActionResult Edit(ArticleCreateViewModel viewModel)
 {
     _articleRepository.Update(viewModel);
     return(RedirectToAction(nameof(ArticleManage)));
 }
        public async Task <IActionResult> CreateArticle([FromBody] ArticleCreateViewModel article)
        {
            if (ModelState.IsValid)
            {
                if (article == null)
                {
                    return(BadRequest($"{nameof(article)} cannot be null"));
                }


                var appArticle = Mapper.Map <Article>(article);

                var appCategory = await _unitOfWork.Categories.GetCategory(Guid.Parse(article.CategoryId));

                if (appCategory == null)
                {
                    return(NotFound("Category not found"));
                }

                appArticle.Category = appCategory;
                appArticle.Slug     = await GenarateUniqueSlug(SlugGenerator.GenerateSlug(article.Title));

                appArticle.Image = "/images/featured/not-found.jpg";

                ICollection <Tag> appTags = new List <Tag>();
                foreach (var tagId in article.TagIds)
                {
                    if (IsValidGuid(tagId))
                    {
                        var appTag = await _unitOfWork.Tags.GetTag(Guid.Parse(tagId));

                        if (appTag == null)
                        {
                            AddError("TagIds", $"TagId: {tagId} not found!");
                        }

                        if (!appTags.Contains(appTag))
                        {
                            appTags.Add(appTag);
                        }
                    }
                    else
                    {
                        AddError("TagIds", $"TagId: {tagId} is not a valid guid");
                    }
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var result = await _unitOfWork.Articles.CreateArticle(appArticle, appTags);

                if (result.Item1)
                {
                    var articleVm = await GetArticleViewModelHelper(appArticle.Id);

                    return(CreatedAtAction(GetArticleActionName, new { id = articleVm.Id }, articleVm));
                }

                AddError("error", result.Item2);
            }

            return(BadRequest(ModelState));
        }