Пример #1
0
        public ActionResult Create(Answer answer, HttpPostedFileBase answerFile, string titleOfFIle, string RtnUrl)
        {
            if (ModelState.IsValid)
            {
			 var q = db.Questions.Find(answer.questionID);
                q.HasAnswer = true;
                answer.ID = Guid.NewGuid();
                answer.DateIn = DateTime.Now;
                answer.LikeCount = 0;
                answer.UnlikeCount = 0;
                answer.isBestAnswer = false;
                var useronline=new AccountController().GetonlineUser_ID();
                answer.UserID =useronline;
                var user = db.MembershipOfSites.Where(x => x.ID == useronline).FirstOrDefault();
                var grade = db.Assistances.Select(x => x.GradeForAnswer).FirstOrDefault();
                user.Grade += grade;
                if (answerFile != null)
                {
                    string filename = titleOfFIle + "--" + new Random().Next(int.MaxValue)+System.IO.Path.GetExtension(answerFile.FileName);
                    answer.filename = filename;
                    answerFile.SaveAs(Server.MapPath("~/Files/AnswerAttachment/" + filename));
                }
                db.Answers.Add(answer);
                db.SaveChanges();
                new UserLogsController().Create(new Log() { ActivityType = ActivityType.Create, CaseActivity = CaseActivity.Answers, QuestionID = answer.questionID, AnswerID = answer.ID });
                return Redirect(RtnUrl);
            }

            ViewBag.fatherAnswer = answer.fatherAnswer;
            ViewBag.qustionID = answer.questionID;
            return View(answer);
        }
Пример #2
0
 public ActionResult Edit(Answer answer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(answer).State = EntityState.Modified;
         new UserLogsController().Create(new Log() { ActivityType = ActivityType.Edit, CaseActivity = CaseActivity.Answers, QuestionID = answer.questionID, AnswerID = answer.ID });
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.UserID = new SelectList(db.MembershipOfSites, "ID", "Name", answer.UserID);
     ViewBag.questionID = new SelectList(db.Questions, "ID", "title", answer.questionID);
     return View(answer);
 }