Ejemplo n.º 1
0
        /// <summary>
        /// 添加实体信息,返回添加成功后的主键ID
        /// </summary>
        public int Insert(WordItem word)
        {
            int id = 0;

            const string sql = @"INSERT INTO WordItem(ChapterID, Title, Image, Answer, Annotation, Difficulty, AddPerson)
                               VALUES (@ChapterID,  @Title, @Image, @Answer, @Annotation, @Difficulty, @AddPerson);
                               SELECT LAST_INSERT_ID();";
            using (DbConnection connection = ConnectionManager.OpenConnection)
            {
                id = connection.Query<int>(sql, word).SingleOrDefault<int>();
            }
            return id;
        }
Ejemplo n.º 2
0
        public WordItemDTO(WordItem wordItem)
        {
            this.ID = wordItem.ID;
            this.ChapterID = wordItem.ChapterID;

            this.Title = wordItem.Title;
            this.Image = wordItem.Image;
            this.Answer = wordItem.Answer;
            this.Annotation = wordItem.Annotation;
            this.Difficulty = wordItem.Difficulty;
            this.AddPerson = wordItem.AddPerson;
            this.AddTime = wordItem.AddTime;
        }
Ejemplo n.º 3
0
        public ActionResult AddWord()
        {
            log.Debug(Constant.DEBUG_START);

            string chapterIDString = ApiQueryUtil.QueryArgByPost("chapter_id");
            string title = ApiQueryUtil.QueryArgByPost("title");
            HttpPostedFileBase imageFile = Request.Files["image"];
            string answer = ApiQueryUtil.QueryArgByPost("answer");
            string difficultyString = ApiQueryUtil.QueryArgByPost("difficulty");

            ServiceInvokeDTO result = null;
            try
            {
                WordItem word = new WordItem();
                word.ChapterID = Convert.ToInt32(chapterIDString);
                word.Title = title;
                word.Answer = answer;
                word.Difficulty = Convert.ToInt32(difficultyString);
                word.AddPerson = (Session[Constant.SESSION_KEY_ADMIN] as Teacher).ChineseName;

                if (imageFile != null)
                {
                    byte[] imageBytes = null;
                    using (Stream inputStream = imageFile.InputStream)
                    {
                        MemoryStream memoryStream = inputStream as MemoryStream;
                        if (memoryStream == null)
                        {
                            memoryStream = new MemoryStream();
                            inputStream.CopyTo(memoryStream);
                        }
                        imageBytes = memoryStream.ToArray();
                    }
                    word.Image = imageBytes;
                }

                result = itemDataService.AddWord(word);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR);
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 更新实体信息
 /// </summary>
 public void Update(WordItem word)
 {
     const string sql = @"UPDATE WordItem SET ChapterID = @ChapterID, Title= @Title,
                        Image = @Image, Answer = @Answer, @Annotation = Annotation, Difficulty = @Difficulty WHERE IsDeleted = 0 AND ID = @ID";
     using (DbConnection connection = ConnectionManager.OpenConnection)
     {
         connection.Execute(sql, word);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加简答题
        /// </summary>
        public ServiceInvokeDTO AddWord(WordItem word)
        {
            log.Debug(Constant.DEBUG_START);
            ServiceInvokeDTO result = null;
            try
            {
                wordDAL.Insert(word);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
            log.Debug(Constant.DEBUG_END);

            return result;
        }