示例#1
0
 public ActionResult DeleteQuestionAnswer(QuestionAnswerViewModel item)
 {
     try
     {
         QuestionAnswer c = db.QuestionAnswers.Find(item.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete question answer " + this.Answer + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
示例#2
0
 public ActionResult AddQuestionAnswer(QuestionAnswerViewModel item)
 {
     try
     {
         QuestionAnswer q = item.ToModel();
         q.CreatedDate = DateTime.Now;
         db.QuestionAnswers.Add(q);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert question answer " + this.Answer + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
示例#3
0
        public ActionResult UpdateQuestionAnswer(QuestionAnswerViewModel item)
        {
            try
            {
                QuestionAnswer c = db.QuestionAnswers.Find(item.ToModel().Id);
                if (c != null)
                {
                    c.Id             = item.Id;
                    c.IsDeleted      = item.IsDeleted;
                    c.ModifiedDate   = DateTime.Now;
                    c.ModifiedUserId = item.ModifiedUserId;
                    c.DeletionDate   = item.DeletionDate;
                    c.DeletionUserId = item.DeletionUserId;
                    c.Answer         = item.Answer;
                    c.OrderNumber    = item.OrderNumber;
                    c.Question       = db.Questions.Find(item.QuestionId);
                    c.QuestionId     = item.QuestionId;
                    c.CreatedUserId  = item.CreatedUserId;
                    //c.CreatedDate = item.CreatedDate;

                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(200));
            }
            catch
            {
                LogViewModel l = new LogViewModel
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Type        = "Update",
                    Message     = "failed to update question answer " + this.Answer + " to database"
                };
                l.AddLog(l);
                return(new HttpStatusCodeResult(400));
            }
        }