Ejemplo n.º 1
0
        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 }) }));
        }
Ejemplo n.º 2
0
        public ActionResult Detail(int WId, int?DId)
        {
            var reader = unitOfWork.ReaderRepository.GetSPDataReader(
                "WDetail",
                new SqlParameter("WId", WId),
                new SqlParameter("isNotEN", ITTConfig.CurrentCultureIsNotEN));

            WordViewModel viewmodel = new WordViewModel();

            Word word = new Word();

            while (reader.Read())
            {
                word.wordId    = reader.GetInt32(0);
                word.lang      = (lang)reader.GetInt32(1);
                word.word      = reader[2] as string;
                word.creatorId = reader.GetInt32(3);
                word.date      = reader.GetDateTime(4);
                word.Creator   = new ActiveUser
                {
                    UserId      = word.creatorId = reader.GetInt32(3),
                    firstName   = reader[5] as string,
                    firstNameEN = reader[5] as string
                };
            }
            viewmodel.word = word;
            reader.NextResult();

            viewmodel.Translates = new List <Word>();
            while (reader.Read())
            {
                Word Translate = new Word();
                Translate.wordId    = reader.GetInt32(0);
                Translate.lang      = (lang)reader.GetInt32(1);
                Translate.word      = reader[2] as string;
                Translate.creatorId = reader.GetInt32(3);
                Translate.date      = reader.GetDateTime(4);
                Translate.Creator   = new ActiveUser
                {
                    UserId      = word.creatorId = reader.GetInt32(3),
                    firstName   = reader[5] as string,
                    firstNameEN = reader[5] as string
                };
                viewmodel.Translates.Add(Translate);
            }
            reader.NextResult();

            viewmodel.Descs = new List <WordDesc>();
            while (reader.Read())
            {
                WordDesc Desc = new WordDesc();
                Desc.descId    = reader.GetInt32(0);
                Desc.desc      = reader[1] as string;
                Desc.creatorId = reader.GetInt32(2);
                Desc.dicId     = reader.GetInt32(3);
                Desc.wordId    = reader.GetInt32(4);
                Desc.date      = reader.GetDateTime(5);
                Desc.edited    = reader[6] as string;
                Desc.Dict      = new Dict
                {
                    dicId = reader.GetInt32(3),
                    name  = reader[8] as string
                };
                Desc.Creator = new ActiveUser
                {
                    UserId      = word.creatorId = reader.GetInt32(2),
                    firstName   = reader[7] as string,
                    firstNameEN = reader[7] as string
                };
                viewmodel.Descs.Add(Desc);
            }
            reader.Close();


            return(View(viewmodel));
        }