示例#1
0
        public ActionResult EditWordSeries([FromBody] SubmitWordsViewModel model)
        {
            int userId = GetUser().Id;

            if (model.Book.Id == 0)
            {
                model.Book.Id = _bookRepository.Add(new Book
                {
                    Name             = model.Book.Name,
                    TargetLanguageId = model.Book.TargetLanguageId,
                    BaseLanguageId   = model.Book.BaseLanguageId
                }, userId).Id;

                if (model.Chapter != null)
                {
                    model.Chapter.Id = _chapterRepository.Add(new Chapter
                    {
                        Name   = model.Chapter.Name,
                        BookId = model.Book.Id,
                    }, userId).Id;
                }
            }

            if (model.Chapter?.Id == 0)
            {
                model.Chapter.Id = _chapterRepository.Add(new Chapter
                {
                    Name   = model.Chapter.Name,
                    BookId = model.Book.Id,
                }, userId).Id;
            }
            _wordRepository.EditWordSeries(new SubmitWordsModel
            {
                BaseLanguage = new NameIdModel {
                    Id = model.BaseLanguage.Id, Name = model.BaseLanguage.Name
                },
                TargetLanguage = new NameIdModel {
                    Id = model.TargetLanguage.Id, Name = model.TargetLanguage.Name
                },
                Book = model.Book != null ? new Book {
                    Id = model.Book.Id
                } : new Book(),
                Chapter = model.Chapter != null ? new Chapter {
                    Id = model.Chapter.Id
                } : new Chapter(),
                Words = model.Words.Select(x => new FormWords
                {
                    Base = new FormWord {
                        Value = x.Base.Value
                    },
                    Targets = x.Targets.Select(y => new FormWord {
                        Value = y.Value
                    }).ToList()
                }).ToList()
            }, userId);
            return(Ok());
        }