예제 #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));
            }
        }
예제 #2
0
        public Result AddElement(MuseumSM model)
        {
            try
            {
                var result = _unitOfWork.ElementRepository.FindBy(x => x.Title.Trim().ToLower() == model.Element.Title.Trim().ToLower());
                if (result.Any())
                {
                    return(new Result(ResultStatus.ALREADYEXISTS));
                }

                var category = _unitOfWork.ElementCategoryRepository.GetById(model.SelectedCategoryId);
                if (category == null)
                {
                    return(new Result(ResultStatus.NOT_FOUND, "Category"));
                }

                var tags = new List <ElementTag>();
                foreach (var item in model.SelectedTagId)
                {
                    var tag = _unitOfWork.ElementTagRepository.GetById(item);
                    if (tag == null)
                    {
                        return(new Result(ResultStatus.NOT_FOUND, "Category"));
                    }
                    tags.Add(tag);
                }

                var elem = model.Element;
                elem.Category     = category;
                elem.MediaElement = _generalService.CreateMediaElements(model.Files, model.Element.DatePublished.Year, "1", ProjectBaseEnum.Muzeum);
                elem.Publisher    = model.Publisher;
                elem.Tags         = tags;

                _unitOfWork.ElementRepository.Add(elem);
                _unitOfWork.SaveChanges();
                return(new Result(ResultStatus.OK));
            }
            catch (Exception ex)
            {
                return(new Result(ResultStatus.EXCEPTION, ex.Message));
            }
        }
예제 #3
0
        public Result <Magazine> Add(Magazine model)
        {
            try
            {
                var category = _unitOfWork.MagazineCategoryRepository.GetById(model.Category.Id);
                if (category == null)
                {
                    return(new Result <Magazine>(ResultStatus.ERROR, "Hiba a kategória lekérése során"));
                }

                model.Category = category;

                var exists = _unitOfWork.MagazineRepository.FindBy(x => x.PublishYear == model.PublishYear && x.PublishSection.Contains(model.PublishSection) && x.Category.Id == model.Category.Id);
                if (exists.Any())
                {
                    return(new Result <Magazine>(ResultStatus.ALREADYEXISTS, "A lapszám már létezik! Kérem ellenőrizze az adatokat!"));
                }

                if (model.Files != null)
                {
                    ICollection <IFormFile> files = new List <IFormFile>();
                    files.Add(model.Files);
                    model.MediaElements = _generalService.CreateMediaElements(files, model.PublishYear, model.PublishSection, ProjectBaseEnum.Gyopar);
                }

                model.DateCreated = DateTime.Now;
                model.Slug        = _generalService.GenerateSlug(model.Title, model.PublishYear, model.PublishSection);
                _unitOfWork.MagazineRepository.Add(model);
                _unitOfWork.SaveChanges();
                return(new Result <Magazine>(model));
            }
            catch (Exception ex)
            {
                return(new Result <Magazine>(ResultStatus.EXCEPTION, ex.Message));
            }
        }