Exemplo n.º 1
0
        public IHttpActionResult Putqa_score(string id, qa_score qa_score)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != qa_score.Id)
            {
                return(BadRequest());
            }

            db.Entry(qa_score).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!qa_scoreExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public IHttpActionResult Postqa_score(qa_score qa_score)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.qa_score.Add(qa_score);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (qa_scoreExists(qa_score.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = qa_score.Id }, qa_score));
        }
Exemplo n.º 3
0
        public IHttpActionResult Getqa_score(string id)
        {
            qa_score qa_score = db.qa_score.Find(id);

            if (qa_score == null)
            {
                return(NotFound());
            }

            return(Ok(qa_score));
        }
Exemplo n.º 4
0
        public IHttpActionResult Deleteqa_score(string id)
        {
            qa_score qa_score = db.qa_score.Find(id);

            if (qa_score == null)
            {
                return(NotFound());
            }

            db.qa_score.Remove(qa_score);
            db.SaveChanges();

            return(Ok(qa_score));
        }
Exemplo n.º 5
0
        public IHttpActionResult Post(AnswerParam param)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var group = db.qa_questions_group.FirstOrDefault(a => a.Id == param.Select_Group);

            if (group == null)
            {
                throw new CheckException("group不存在");
            }

            var qData = JsonConvert.DeserializeObject <List <qa_questionsView> >(param.SelectVar);
            var ids   = new List <string>();

            GetIds(qData, ids);

            List <qa_answer> qas = new List <qa_answer>();

            foreach (var item in ids)
            {
                var q = db.qa_questions.FirstOrDefault(a => a.Id == item);
                if (q != null)
                {
                    var qa = new qa_answer();
                    qa.Id                 = Guid.NewGuid().ToString();
                    qa.LastUpdateUser     = qa.Creater = "1";
                    qa.LastUpdateUserName = qa.CreaterName = "测试";
                    qa.LastUpdateTime     = qa.CreateTime = DateTime.Now;
                    qa.Status             = (sbyte)DataState.Normal;
                    qa.StatusDesc         = DataState.Normal.GetDescription();
                    qa.LastUpdateUser     = param.Select_Group;
                    qa.wt_id              = q.Id;
                    qa.wt_score           = q.score;
                    qa.dtr_id             = param.UserName;
                    qas.Add(qa);
                }
            }
            db.qa_answer.AddRange(qas);
            var score = qas.Sum(a => a.wt_score);

            var qa_score = new qa_score();

            qa_score.Id                 = Guid.NewGuid().ToString();
            qa_score.LastUpdateUser     = qa_score.Creater = "1";
            qa_score.LastUpdateUserName = qa_score.CreaterName = param.UserName;
            qa_score.LastUpdateTime     = qa_score.CreateTime = DateTime.Now;
            qa_score.Status             = (sbyte)DataState.Normal;
            qa_score.StatusDesc         = DataState.Normal.GetDescription();
            qa_score.score              = score;
            qa_score.tz_id              = param.Select_Group;
            qa_score.tz_name            = group.Name;
            qa_score.dtr_id             = param.UserName;
            db.qa_score.Add(qa_score);


            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (qa_questionsExists(qa_score.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = qa_score.Id }, param));
        }