Example #1
0
        public Task<string> Create(WordModel model)
        {
            if (!model.IsValidForNew())
            {
                return null;
            }

            var slug = model.Key.ToUrlSlug();
            if (_wordRepository.Set<Word>().Any(x => x.Key == slug))
            {
                return null;
            }

            var tags = new List<Tag>();
            if (!string.IsNullOrEmpty(model.Tag))
            {
                var items = model.Tag.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var item in items)
                {
                    tags.Add(new Tag
                    {
                        CreatedBy = model.CreatedBy,
                        Name = item,
                        UrlName = item.ToUrlSlug()
                    });
                }
            }

            var word = new Word
            {
                Key = slug,
                Description = model.Description ?? string.Empty,
                IsTranslated = false,
                TranslationCount = 0,
                CreatedBy = model.CreatedBy,
                UpdatedBy = model.CreatedBy,
                Tags = tags
            };

            _wordRepository.Create(word);
            _wordRepository.SaveChanges();

            if (word.Id < 1)
            {
                return null;
            }

            return Task.FromResult(word.Key);
        }
Example #2
0
        public async Task<ActionResult> New(WordModel model)
        {
            if (!model.IsValidForNew())
            {
                model.Msg = "bir sorun oluştu";
                return View(model);
            }

            model.CreatedBy = User.Identity.GetUserId();
            
            var key = await _wordService.Create(model);
            if (key == null)
            {
                model.Msg = "bir sorun oluştu, daha önce eklenmiş olabilir";
                return View(model);
            }

            return Redirect("/word/detail/" + key);
        }
Example #3
0
        public Task<string> Update(WordModel model)
        {
            if (!model.IsValidForNew())
            {
                return null;
            }

            var slug = model.Key.ToUrlSlug();

            var wordEntity = _wordRepository.FindOne(x => x.Key == slug);
            if (wordEntity == null) return Create(model);

            _wordRepository.SoftDelete(wordEntity.Id, model.CreatedBy);
            _wordRepository.SaveChanges();

            return Create(model);
        }