Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        public async Task <PublicJsonResult> UpdateAsync(TaxonomyInput input)
        {
            var tax = await _taxonomyRepository.GetByIdAsync(input.Id);

            if (tax == null)
            {
                throw new Exception("Taxonomy not found");
            }

            //بررسی یکتا بودن عنوان
            var existTax = await _taxonomyRepository.GetByNameAsync(input.Name.Trim());

            if (existTax != null && existTax.Id != input.Id)
            {
                return new PublicJsonResult {
                           result = false, message = Messages.Post_Title_Already_Exist
                }
            }
            ;


            //بررسی نامک -- url friendly
            tax.UrlTitle    = input.UrlTitle.IsNullOrEmptyOrWhiteSpace() ? input.Name.GenerateUrlTitle() : input.UrlTitle.GenerateUrlTitle();
            tax.Name        = input.Name;
            tax.Description = input.Name;


            await _taxonomyRepository.UpdateAsync(tax);

            return(new PublicJsonResult {
                result = true, message = Messages.Post_Update_Success
            });
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        public async Task <PublicJsonResult> CreateAsync(TaxonomyInput input)
        {
            //بررسی یکتا بودن عنوان
            var existTax = await _taxonomyRepository.GetByNameAsync(input.Name.Trim());

            if (existTax != null)
            {
                return new PublicJsonResult {
                           result = false, message = Messages.Post_Title_Already_Exist
                }
            }
            ;

            //بررسی نامک -- url friendly
            input.UrlTitle = input.UrlTitle.IsNullOrEmptyOrWhiteSpace() ? input.Name.GenerateUrlTitle() : input.UrlTitle.GenerateUrlTitle();

            var post = new Taxonomy
            {
                Id          = input.Id,
                Name        = input.Name,
                Description = input.Description,
                PostCount   = input.PostCount,
                Type        = input.Type,
                UrlTitle    = input.UrlTitle,
            };

            await _taxonomyRepository.CreateAsync(post);

            return(new PublicJsonResult {
                result = true, id = post.Id, message = Messages.Post_Create_Success
            });
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 public Taxonomy BindToDomainModel(TaxonomyInput input)
 {
     return(new Taxonomy
     {
         Name = input.Name,
         Description = input.Description,
         PostCount = input.PostCount,
         Type = input.Type,
         UrlTitle = input.UrlTitle,
     });
 }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        public async Task <PublicJsonResult> CreateAsync(TaxonomyInput input)
        {
            //بررسی یکتا بودن عنوان
            var existTax = await _taxonomyRepository.GetByNameAsync(input.Name.Trim());

            if (existTax != null)
            {
                return new PublicJsonResult {
                           Result = false, Message = Messages.Post_Title_Already_Exist
                }
            }
            ;

            //بررسی نامک -- url friendly
            input.UrlTitle = input.UrlTitle.IsNullOrEmptyOrWhiteSpace() ? input.Name.GenerateUrlTitle() : input.UrlTitle.GenerateUrlTitle();

            var taxonomy = _mapperService.BindToDomainModel(input);

            await _taxonomyRepository.CreateAsync(taxonomy);

            return(new PublicJsonResult {
                Result = true, Id = taxonomy.Id, Message = Messages.Post_Create_Success
            });
        }