Ejemplo n.º 1
0
        public ActionResult EditArticle(ArticleEditViewModel model)
        {
            var userRepo = new UserRepository();
            //var categoryRepo = new CategoryRepository();
            var repo = new ArticleRepository();

            model.User = new SelectList(userRepo.GetAll(), "UserId", "UserName");
            //model.Categories = new SelectList(categoryRepo.GetAll(), "CategoryId", "CategoryName");
            // model.Article = repo.GetById(model.Article.ArticleId);

            if (User.Identity.IsAuthenticated)
            {
                var user = User.Identity;
                ViewBag.Name = user.Name;

                ViewBag.displayMenu = "No";

                if (IsAdminUser())
                {
                    ViewBag.displayMenu = "Yes";
                }
                repo.UpdateArticle(model.Article);
                //return View(model);
                return(RedirectToAction("Articles", "Admin"));
            }
            else
            {
                ViewBag.Name = "Not Logged IN";
            }

            return(RedirectToAction("Inventory", "Admin"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditArticle(ArticleEditViewModel model, IFormFile pic)
        {
            var article = _articleService.GetById(model.Id);

            if (ModelState.IsValid)
            {
                var titleConv = new TitleConverter();
                var urlConv   = new UrlConverter();

                if (pic != null)
                {
                    var extension = Path.GetExtension(pic.FileName);
                    var name      = urlConv.StringReplace(model.Title) + extension;
                    var path      = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/article-cover/" + name);
                    using var stream = new FileStream(path, FileMode.Create);
                    await pic.CopyToAsync(stream);

                    model.Picture = name;

                    article.Picture = model.Picture;
                }
                article.Title      = titleConv.TitleToPascalCase(model.Title);
                article.Content    = model.Content.Replace("&nbsp;", " ");
                article.Url        = urlConv.StringReplace(model.Title);
                article.CategoryId = model.CategoryId;
                _articleService.Update(article);

                return(RedirectToAction("Index", "Article", new { area = "Admin" }));
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult EditArticle(int id)
        {
            var model    = new ArticleEditViewModel();
            var userRepo = new UserRepository();
            var repo     = new ArticleRepository();

            model.User = new SelectList(userRepo.GetAll(), "UserId", "UserName");

            model.Article = repo.GetById(id);

            //if (User.Identity.IsAuthenticated)
            //{
            //    var user = User.Identity;
            //    ViewBag.Name = user.Name;

            //    ViewBag.displayMenu = "No";

            //    if (IsAdminUser())
            //    {
            //        ViewBag.displayMenu = "Yes";
            //    }
            return(View(model));
            //}
            //else
            //{
            //    ViewBag.Name = "Not Logged IN";
            //}
            //return RedirectToAction("Inventory", "Admin"); ;
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutArticle([FromRoute] int id, [FromBody] ArticleEditViewModel article)
        {
            string log = $"PUT request: article, id={id}" + Environment.NewLine +
                         $"From IP: {_accessor.HttpContext.Connection.RemoteIpAddress.ToString()}" + Environment.NewLine;

            if (!ModelState.IsValid)
            {
                log += "Bad model state";
                _logger.LogError(log);

                return(BadRequest(ModelState));
            }

            var target_article = await _context.Articles.SingleOrDefaultAsync(m => m.Id == id);

            var entry = new Article
            {
                Id              = target_article.Id,
                Title           = (string.IsNullOrWhiteSpace(article.Title) ? target_article.Title : article.Title).Trim(),
                Body            = (string.IsNullOrWhiteSpace(article.Body) ? target_article.Body : article.Body).Trim(),
                PreviewText     = (string.IsNullOrWhiteSpace(article.PreviewText) ? target_article.PreviewText : article.PreviewText).Trim(),
                PreviewImageUri = (string.IsNullOrWhiteSpace(article.PreviewImageUri) ? target_article.PreviewImageUri : article.PreviewImageUri).Trim(),
                CreateAt        = target_article.CreateAt,
                LastEditAt      = DateTime.Now,
                DisplayLevel    = target_article.DisplayLevel,
                ImageUris       = target_article.ImageUris,
                Status          = target_article.Status,
                Language        = target_article.Language
            };

            _context.DetachLocalInstance <Article>(id);
            _context.Entry(entry).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleExists(id))
                {
                    log += "The article does not exist";
                    _logger.LogWarning(log);

                    return(NotFound());
                }
                else
                {
                    log += "The database is busy";
                    _logger.LogWarning(log);

                    throw;
                }
            }

            log += "Result: article has been updated";
            _logger.LogInformation(log);

            return(Ok(entry));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Edit(int id)
        {
            var response = await this.articleService.GetEditArticleAsync(new GetArticleRequest
            {
                ArticleId = id
            });

            if (response.Status == StatusCode.OK)
            {
                var model = new ArticleEditViewModel
                {
                    Article   = response.Article,
                    Languages = this.GetLanguageListItems()
                };

                return(View(model));
            }
            else if (response.Status == StatusCode.NotFound)
            {
                return(this.HttpNotFound());
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 6
0
        public IActionResult Edit([FromForm] ArticleEditViewModel viewModel)
        {
            var dbArticle = _dbContext.Articles.FirstOrDefault(l => l.Id == viewModel.Id);

            if (dbArticle == null)
            {
                RedirectToAction("Index");
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            _mapper.Map(viewModel, dbArticle);

            if (viewModel.CertificateUpload != null)
            {
                _fileService.DeleteFile(dbArticle.Certificate);
                dbArticle.Certificate = _fileService.SaveFile(viewModel.CertificateUpload);
            }

            if (viewModel.SafteyListUpload != null)
            {
                _fileService.DeleteFile(dbArticle.SafteyList);
                dbArticle.SafteyList = _fileService.SaveFile(viewModel.SafteyListUpload);
            }

            _dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public async Task EditAsync(ArticleEditViewModel articleEditViewModel, string userId)
        {
            var article = await this.articlesRepository
                          .All()
                          .FirstOrDefaultAsync(a => a.Id == articleEditViewModel.Id);

            if (article == null)
            {
                throw new NullReferenceException(
                          string.Format(ExceptionMessages.ArticleNotFound, articleEditViewModel.Id));
            }

            if (articleEditViewModel.Image != null)
            {
                var newImageUrl = await this.cloudinaryService
                                  .UploadAsync(articleEditViewModel.Image, articleEditViewModel.Title + Suffixes.ArticleSuffix);

                article.ImagePath = newImageUrl;
            }

            article.Title       = articleEditViewModel.Title;
            article.Description = articleEditViewModel.Description;
            article.UserId      = userId;
            article.CategoryId  = articleEditViewModel.CategoryId;

            this.articlesRepository.Update(article);
            await this.articlesRepository.SaveChangesAsync();
        }
        public async Task TestEditingArticleWithMissingArticle()
        {
            await this.SeedUsers();

            await this.SeedCategories();

            var path = "Test.jpg";

            ArticleEditViewModel model;

            using (var img = File.OpenRead(path))
            {
                var testImage = new FormFile(img, 0, img.Length, "Test.jpg", img.Name)
                {
                    Headers     = new HeaderDictionary(),
                    ContentType = "image/jpeg",
                };

                model = new ArticleEditViewModel
                {
                    Id          = 1,
                    Title       = "TestEditTitle",
                    Description = this.firstArticle.Description,
                    Image       = testImage,
                    CategoryId  = 1,
                };
            }

            var exception = await Assert
                            .ThrowsAsync <NullReferenceException>(async() => await this.articlesService.EditAsync(model, this.cookingHubUser.Id));

            Assert.Equal(string.Format(ExceptionMessages.ArticleNotFound, model.Id), exception.Message);
        }
Ejemplo n.º 9
0
        public ActionResult Edit(int aidx)
        {
            ArticleEditViewModel vm      = new ArticleEditViewModel();
            Articles             article = db.Articles.Where(c => c.ArticleIDX == aidx).FirstOrDefault();
            List <ArticleFiles>  files   = db.ArticleFiles.Where(c => c.ArticleIDX == aidx).OrderBy(o => o.UploadDate).ToList();

            vm.Article = article;
            vm.Files   = files;

            return(View(vm));
        }
Ejemplo n.º 10
0
        public ActionResult Edit(ArticleEditViewModel vm)
        {
            ArticleEditViewModel dbVM = new ArticleEditViewModel();

            try
            {
                Articles dbArticle = db.Articles.Find(vm.Article.ArticleIDX);

                dbArticle.Title          = vm.Article.Title;
                dbArticle.Category       = vm.Article.Category;
                dbArticle.Contents       = vm.Article.Contents;
                dbArticle.IPAddress      = vm.Article.IPAddress;
                dbArticle.ModifyDate     = DateTime.Now;
                dbArticle.ModifyMemberID = "admin";

                db.Entry(dbArticle).State = EntityState.Modified;
                db.SaveChanges();

                if (Request.Files.Count > 0)
                {
                    var attachFile = Request.Files[0];

                    if (attachFile != null && attachFile.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(attachFile.FileName);
                        var path     = Path.Combine(Server.MapPath("~/Upload/"), fileName);
                        attachFile.SaveAs(path);

                        ArticleFiles file = new ArticleFiles();
                        file.ArticleIDX = vm.Article.ArticleIDX;
                        file.FilePath   = "/Upload/";
                        file.FileName   = fileName;
                        file.FileFormat = Path.GetExtension(attachFile.FileName);
                        file.FileSize   = attachFile.ContentLength;
                        file.UploadDate = DateTime.Now;

                        db.ArticleFiles.Add(file);
                        db.SaveChanges();
                    }
                }

                Articles            article = db.Articles.Where(c => c.ArticleIDX == vm.Article.ArticleIDX).FirstOrDefault();
                List <ArticleFiles> files   = db.ArticleFiles.Where(c => c.ArticleIDX == vm.Article.ArticleIDX).OrderBy(o => o.UploadDate).ToList();

                dbVM.Article   = article;
                dbVM.Files     = files;
                ViewBag.Result = "OK";
            } catch (Exception ex)
            {
                dbVM           = vm;
                ViewBag.Result = "FAIL";
            }
            return(View(dbVM));
        }
        //
        // GET: /Article/Edit/5
        public ActionResult Edit(int articleId)
        {
            var viewModel = new ArticleEditViewModel()
            {
                Article = _articles.RetrieveById(articleId),
                Authors = _authors.RetrieveAll(),
                Tags    = _tags.RetrieveAll()
            };

            return(View(viewModel));
        }
        //
        // GET: /Article/Create
        public ActionResult Create()
        {
            var viewModel = new ArticleEditViewModel()
            {
                Article = new Article(),
                Authors = _authors.RetrieveAll(),
                Tags    = _tags.RetrieveAll()
            };

            return(View(viewModel));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> Edit(ArticleEditViewModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(editModel));
            }

            GetArticleModel updatedModel = await Mediator.Send(new UpdateArticleCommand(editModel.ArticleId, editModel.PostArticleModel));

            return(RedirectToAction("Details", new { id = updatedModel.Id }));
        }
Ejemplo n.º 14
0
        public IActionResult Edit(int id)
        {
            var oldArticle = _articleLogic.GetBy(id);

            var viewmodel = new ArticleEditViewModel
            {
                Calories = oldArticle.Calories,
                Name     = oldArticle.Name
            };

            return(View(viewmodel));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> EditArticle(int id)
        {
            Article article = await _newsRepository.GetByIdAsync(id);

            var model = new ArticleEditViewModel
            {
                Id    = article.Id,
                Title = article.Title,
                Body  = article.Body
            };

            return(View(model));
        }
Ejemplo n.º 16
0
        private void MainViewModel_CreateArticle(object sender, EventArgs e)
        {
            ArticleEditViewModel vm         = new ArticleEditViewModel(persistence, null);
            ArticleEditWindow    editWindow = new ArticleEditWindow();

            vm.BackEvent += (object o, EventArgs ea) =>
            {
                editWindow.Close();
            };
            vm.MessageApplication += ViewModel_MessageApplication;
            editWindow.DataContext = vm;
            editWindow.ShowDialog();
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> EditArticle(ArticleEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Article article = await _newsRepository.GetByIdAsync(model.Id);

            article.Edit(model.Title, model.Body);

            await _newsRepository.UpdateAsync(article);

            return(RedirectToAction("GetMyArticles"));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> PublishArticle(ArticleEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            IdentityUser user = await _userManager.FindByNameAsync(User.Identity.Name);

            var article = new Article(model.Title, model.Body, user.Id);

            await _newsRepository.AddAsync(article);

            return(RedirectToAction("GetMyArticles"));
        }
Ejemplo n.º 19
0
        public IActionResult EditArticle(int id)
        {
            TempData["Active"] = "article";
            ViewBag.Title      = "Makale Düzenle";
            ViewBag.Categories = new SelectList(_categoryService.GetAll(), "Id", "Name");
            var article = _articleService.GetById(id);
            var model   = new ArticleEditViewModel()
            {
                Id         = article.Id,
                Title      = article.Title,
                Content    = article.Content,
                CategoryId = article.CategoryId,
                Picture    = article.Picture
            };

            return(View(model));
        }
Ejemplo n.º 20
0
        public ActionResult Add()
        {
            ArticleEditViewModel vm = new ArticleEditViewModel
            {
                Article = new Article()
                {
                    PublishTime = DateTime.Now
                },
                Categories  = _articleService.GetCategoriesSortArray(),
                ArticleTags = new List <string>(),
                Tags        = _articleService.GetTagsDict().Keys.ToList()
            };

            ViewBag.Title = "撰写文章";

            return(View("Detail", vm));
        }
Ejemplo n.º 21
0
        public IActionResult Edit(int id, ArticleEditViewModel data)
        {
            var article = new Article
            {
                Id       = id,
                Calories = data.Calories,
                Name     = data.Name,
            };

            if (_articleLogic.Edit(AuthController.GetAuthUserId(User), article))
            {
                return(RedirectToAction("List", "Article"));
            }

            ViewData["message"] = "Er ging iets fout tijdens het wijzigen";
            return(View(data));
        }
Ejemplo n.º 22
0
        public ActionResult Edit(string id)
        {
            id = HttpUtility.UrlDecode(id);
            DataServiceMessage <ArticleEditDTO> serviceMessage = articleService.Get(id);

            if (serviceMessage.Succeeded)
            {
                ArticleEditViewModel model = Mapper.Map <ArticleEditDTO, ArticleEditViewModel>(serviceMessage.Data);
                var categoryNames          = GetAllCategoryNames();
                model.Categories = ConvertToSelectListItems(categoryNames);
                return(ActionResultDependingOnGetRequest(model));
            }
            else
            {
                return(Error(serviceMessage.Errors));
            }
        }
Ejemplo n.º 23
0
        public ActionResult Edit(ArticleEditViewModel articleEditVM)
        {
            if (!ModelState.IsValid)
            {
                return(View("Views/BlogEditView", articleEditVM));
            }
            Article article = bService.GetArticle(articleEditVM.Id);

            if (article.Content == articleEditVM.Content && article.Title == articleEditVM.Title)
            {
                return(RedirectToAction("Detail", new { id = article.Id }));
            }
            if (article.UserId == _currentUserId || User.IsInRole("Administrator") || User.IsInRole("Moderator") || User.IsInRole("Expert"))
            {
                article.Title   = articleEditVM.Title;
                article.Content = articleEditVM.Content;
                article.Privacy = articleEditVM.Privacy == 0 ? article.Privacy : articleEditVM.Privacy;
                if (article.UserId == _currentUserId)
                {
                    article.PublicDate = articleEditVM.PublicDate.Value;
                }
                if (article.PublicDate <= DateTime.Now)
                {
                    EditedLog editedlog = new EditedLog();
                    editedlog.Content      = articleEditVM.Content;
                    editedlog.CreatedDate  = DateTime.Now;
                    editedlog.PostId       = article.Id;
                    editedlog.Title        = articleEditVM.Title;
                    editedlog.UserId       = User.Identity.GetUserId <int>();
                    article.LastEditedDate = editedlog.CreatedDate;
                    article.EditedContents.Add(editedlog);
                }
                bService.UpdateArticle(article);

                return(RedirectToAction("Detail", new { id = article.Id }));
            }
            //string returnUrl = Request.Cookies.Get("returnUrl") != null ? Request.Cookies.Get("returnUrl").Value : default(string);
            if (_previousUrl == default(string))
            {
                return(RedirectToAction("Detail", new { id = article.Id }));
            }
            else
            {
                return(Redirect(Url.Content(_previousUrl)));
            }
        }
Ejemplo n.º 24
0
        public async Task <ViewResult> Edit(int id)
        {
            var article = await Mediator.Send(new GetArticleQuery(id));

            var model = new ArticleEditViewModel
            {
                ArticleId        = id,
                PostArticleModel = new PostArticleModel
                {
                    BoardId = article.BoardId,
                    Text    = article.Text,
                    Title   = article.Title,
                    Type    = article.Type.ToString()
                }
            };

            return(View(model));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Edit(ArticleEditViewModel articleEditViewModel)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            if (!this.ModelState.IsValid)
            {
                var categories = await this.categoriesService
                                 .GetAllCategoriesAsync <CategoryDetailsViewModel>();

                articleEditViewModel.Categories = categories;

                return(this.View(articleEditViewModel));
            }

            await this.articlesService.EditAsync(articleEditViewModel, user.Id);

            return(this.RedirectToAction("GetAll", "Articles", new { area = "Administration" }));
        }
Ejemplo n.º 26
0
        public async Task <ActionResult> Edit(ArticleEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var response = await this.articleService.UpdateArticleAsync(model.Article);

                if (response.Status == StatusCode.OK)
                {
                    TempData["SuccessMessage"] = string.Format("You have successfully updated '{0}'.", response.Article.Title);
                }
                else
                {
                    TempData["FailureMessage"] = "An error has occurred and the article has not been updated.";
                }

                return(this.RedirectToAction("Index"));
            }

            return(View());
        }
        public ActionResult Edit(Article article)
        {
            try
            {
                _articles.Update(ParseTags(article));
                return(RedirectToAction("Index"));
            }
            catch (Exception exception)
            {
                ViewBag.ErrorMessage = exception.Message;
                var viewModel = new ArticleEditViewModel()
                {
                    Article = article,
                    Authors = _authors.RetrieveAll(),
                    Tags    = _tags.RetrieveAll()
                };

                return(View(viewModel));
            }
        }
Ejemplo n.º 28
0
        public ActionResult Detail(int id)
        {
            var article = _articleService.GetArticle(id);

            if (article == null)
            {
                return(RedirectToAction("Index"));
            }

            ArticleEditViewModel vm = new ArticleEditViewModel
            {
                Article     = article,
                Categories  = _articleService.GetCategoriesSortArray(),
                ArticleTags = _articleService.GetArticleTags(id).Select(d => d.Name).ToList(),
                Tags        = _articleService.GetTagsDict().Keys.ToList()
            };

            ViewBag.Title = string.Format("编辑 - " + article.Title);

            return(View(vm));
        }
Ejemplo n.º 29
0
        public IActionResult Edit(int id)
        {
            var dbArticle = _dbContext.Articles
                            .Include(s => s.Certificate)
                            .Include(s => s.SafteyList)
                            .FirstOrDefault(l => l.Id == id);

            if (dbArticle == null)
            {
                RedirectToAction("Index");
            }

            var viewModel = new ArticleEditViewModel
            {
                StorageTypes     = GetStorageTypes(),
                StorageLocations = GetStorageLocations(),
                WorkLocations    = GetWorkLocations(),
                Analysers        = GetAnalysers(),
                CatalogArticles  = GetCatalogArticles()
            };

            return(View(_mapper.Map(dbArticle, viewModel)));
        }
Ejemplo n.º 30
0
        public ActionResult Edit(ArticleEditViewModel model)
        {
            var categoryNames = GetAllCategoryNames();

            model.Categories = ConvertToSelectListItems(categoryNames);

            bool success = false;

            if (ModelState.IsValid)
            {
                model.Id = HttpUtility.UrlDecode(model.Id);
                ArticleEditDTO articleDTO     = Mapper.Map <ArticleEditViewModel, ArticleEditDTO>(model);
                ServiceMessage serviceMessage = articleService.Edit(articleDTO);
                if (!serviceMessage.Succeeded)
                {
                    AddModelErrors(serviceMessage.Errors);
                }

                success = serviceMessage.Succeeded;
            }

            return(JsonOnFormPost(success, "~/Views/Article/Edit.cshtml", model));
        }
Ejemplo n.º 31
0
 public ActionResult Edit(ArticleEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (this.ArticleService.Edit(model))
         {
             return this.RedirectToAction("Index");
         }
     }
     this.ViewBag.Error = "Unable to save!";
     return this.View(model);
 }
Ejemplo n.º 32
0
        public async Task<ActionResult> Edit(int id)
        {
            var response = await this.articleService.GetEditArticleAsync(new GetArticleRequest
            {
                ArticleId = id
            });

            if (response.Status == StatusCode.OK)
            {
                var model = new ArticleEditViewModel
                {
                    Article = response.Article,
                    Languages = this.GetLanguageListItems()
                };

                return View(model);
            }
            else if (response.Status == StatusCode.NotFound)
            {
                return this.HttpNotFound();
            }
            else
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
            }
        }
Ejemplo n.º 33
0
        public async Task<ActionResult> Create(ArticleEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.Article.LanguageId = 1;
                var response = await this.articleService.CreateArticleAsync(model.Article);
                if (response.Status == StatusCode.OK)
                {
                    TempData["SuccessMessage"] = string.Format("You have successfully added '{0}' as a new article.", response.Article.Title);
                }
                else
                {
                    TempData["FailureMessage"] = "An error has occurred and the article has not been created.";
                }

                return this.RedirectToAction("Index");
            }

            return View();
        }