Пример #1
0
        public ActionResult Edit([Deserialize] WordEditVars mdl, int?WId, string edited)
        {
            var word = unitOfWork.WordRepository.GetByID(mdl.mainWId);

            if (word.Descs.Any(d => d.dicId == mdl.DId))
            {
                if (WId == null)
                {
                    if (unitOfWork.WordRepository.Get(d => d.word == edited).Count() > 0)
                    {
                        throw new JsonCustomException(ControllerError.ajaxErrorWordDuplicate);
                    }
                }
                var current = unitOfWork.WordEditRepository.Get(d =>
                                                                d.editorId == WebSecurity.CurrentUserId &&
                                                                d.dicId == mdl.DId &&
                                                                d.wordId == mdl.mainWId).SingleOrDefault();

                if (current != null)
                {
                    current.sugWordId = WId;
                    current.text      = edited;
                    unitOfWork.WordEditRepository.Update(current);
                }
                else
                {
                    WordEdit wordedit = new WordEdit();
                    wordedit.date      = DateTime.UtcNow;
                    wordedit.dicId     = mdl.DId;
                    wordedit.wordId    = mdl.mainWId;
                    wordedit.sugWordId = WId;
                    wordedit.text      = edited;

                    wordedit.editorId = WebSecurity.CurrentUserId;

                    unitOfWork.WordEditRepository.Insert(wordedit);
                }

                unitOfWork.Save();
                return(Json(new { Url = Url.Action("Edit", "Word", new { WId = word.wordId, DId = mdl.DId }) }));
            }
            throw new JsonCustomException(ControllerError.ajaxError);
        }
Пример #2
0
        public ActionResult Edit(int WId, int DId)
        {
            var reader = unitOfWork.ReaderRepository.GetSPDataReader(
                "WordAndEdits",
                new SqlParameter("DId", DId),
                new SqlParameter("WId", WId),
                new SqlParameter("isNotEN", ITTConfig.CurrentCultureIsNotEN));
            WordEditVars model = new WordEditVars();

            if (reader.Read())
            {
                var dicInfo = new DicInfo
                {
                    name = reader[3] as string
                };
                model = new WordEditVars
                {
                    DId     = DId,
                    mainWId = reader.GetInt32(0),
                    word    = reader[1] as string,
                    lang    = (lang)reader.GetInt32(2),
                    dicInfo = dicInfo
                };
            }
            reader.NextResult();
            model.wordEditgs = new List <WordEditwithScore>();
            while (reader.Read())
            {
                model.wordEditgs.Add(new WordEditwithScore
                {
                    editId      = reader.GetInt32(0),
                    sugWordId   = reader[1] as int?,
                    text        = reader[2] as string,
                    editorId    = reader.GetInt32(3),
                    date        = reader.GetDateTime(4),
                    editorName  = reader[5] as string,
                    editorIMage = reader[6] as string,
                    Score       = reader[7] as int?
                });
            }
            return(View(model));
        }