Example #1
0
        public Result AddElement(H_Article model)
        {
            try
            {
                var result = _unitOfWork.HElementRepository.FindBy(x => x.Title.Trim().ToLower() == model.Title.Trim().ToLower());

                if (result.Any())
                {
                    return(new Result(ResultStatus.ALREADYEXISTS));
                }

                var author = _unitOfWork.AuthorRepository.FindBy(x => x.Name == model.Author.Name).FirstOrDefault();
                model.Author = model.Author.Id == 0 ? new Author {
                    Name = model.Author.Name
                } : _unitOfWork.AuthorRepository.GetById(model.Author.Id);

                if (model.Files != null)
                {
                    model.MediaElements = _generalService.CreateMediaElements(model.Files, model.DateAdded.Year, "1", ProjectBaseEnum.Main);
                }
                model.Slug = _generalService.GenerateSlug(model.Title, model.DateAdded.Year, "1");

                _unitOfWork.HElementRepository.Add(model);
                _unitOfWork.SaveChanges();

                return(new Result(ResultStatus.OK));
            }
            catch (Exception ex)
            {
                return(new Result(ResultStatus.EXCEPTION, ex.Message));
            }
        }
Example #2
0
 public List <MediaElement> SolveMediaElements(H_Article article)
 {
     if (!article.MediaElements.Any())
     {
         return(new List <MediaElement>()
         {
             new MediaElement()
             {
                 OriginalName = "Uploads/2018/1/r1_7CRBGH1C5Y_download (1).jpg",
                 Name = "7CRBGH1C5Y_download(1).jpg"
             }
         });
     }
     return(article.MediaElements.ToList());
 }
Example #3
0
        public IActionResult AddElement(H_Article model)
        {
            if (ModelState.IsValid)
            {
                model.PublishedBy = User.Identity.Name;

                var result = _mainService.AddElement(model);
                if (result.IsOk())
                {
                    return(RedirectToAction("EditElem"));
                }
            }

            TempData["ErrorMessage"] = string.Format("Hiba a hozzáadás során: Nem létező paraméter");
            return(RedirectToAction("EditElem"));
        }