public ActionResult Create(WordVars model, [Deserialize] DicInfo info) { var dic = unitOfWork.DictionaryRepository.GetByID(info.id); Word word = new Word(); if (model.WId == null) { if (unitOfWork.WordRepository.Get(d => d.word == model.word).Count() > 0) { throw new JsonCustomException(model.lang == lang.en ? ControllerError.ajaxErrorWordDuplicateEn : ControllerError.ajaxErrorWordDuplicateFa); } word.lang = model.lang; word.word = model.word; word.date = DateTime.UtcNow; word.creatorId = WebSecurity.CurrentUserId; WordDesc enWordDesc = new WordDesc(); enWordDesc.dicId = info.id; enWordDesc.desc = model.wordDesc; enWordDesc.date = DateTime.UtcNow; enWordDesc.creatorId = WebSecurity.CurrentUserId; if (word.Descs == null) { word.Descs = new List <WordDesc>(); } word.Descs.Add(enWordDesc); unitOfWork.WordRepository.Insert(word); } else { word = unitOfWork.WordRepository.GetByID(model.WId); if (!word.Descs.Any(d => d.dicId == info.id)) { WordDesc enWordDesc = new WordDesc(); enWordDesc.dicId = info.id; enWordDesc.desc = model.wordDesc; enWordDesc.date = DateTime.UtcNow; enWordDesc.creatorId = WebSecurity.CurrentUserId; if (word.Descs == null) { word.Descs = new List <WordDesc>(); } word.Descs.Add(enWordDesc); } unitOfWork.WordRepository.Update(word); } unitOfWork.Save(); return(Json(new { Url = Url.Action("AddTranslate", "Word", new { WId = word.wordId, DId = dic.dicId }) })); }
public ActionResult Create(int DId) { var dic = unitOfWork.DictionaryRepository.GetByID(DId); DicInfo dinfo = new DicInfo { name = dic.name, id = dic.dicId }; WordVars model = new WordVars { dicInfo = dinfo }; return(View(model)); }