public ActionResult UploadComment(UploadCommentViewModel model, int id) { int usrId = (int)HttpContext.Session["usrId"]; if (ModelState.IsValid) { using (SSDBEntities db = new SSDBEntities()) { Comments c = new Comments(); c.CommentTime = DateTime.Now; c.NewScore = model.NewScore; c.ReceiverId = usrId; c.SimilarScore = model.SimilarScore; c.Text = model.Text; c.ThingId = id; c.UsefulScore = model.UsefulScore; c.BeautifulScore = model.BeautifulScore; c.SpeedScore = model.SpeedScore; db.Comments.Add(c); Assess a = db.Assess.Where(x => x.UserId == usrId).FirstOrDefault(); a.CreditPoint += 1; a.CreditLevel = CreditFunction.GetCreditLevel(a.CreditPoint.Value); db.Entry(a).State = EntityState.Modified; db.SaveChanges(); } } else { return(View(model)); } return(RedirectToAction("MyQuestsList")); }
// GET: 查看评论捐赠物品界面 public ActionResult UploadComment(int id) { UploadCommentViewModel res = new UploadCommentViewModel(); using (SSDBEntities db = new SSDBEntities()) { Things t = db.Things.Where(x => x.Id == id).FirstOrDefault(); Users tu = db.Users.Where(x => x.UserId == t.DonatorId).FirstOrDefault(); res.Thing = t; res.Donator = tu; } return(View(res)); }
public async Task <ActionResult> UploadComment(UploadCommentViewModel model) { if (!(await Authorized())) { return(RedirectToAction("Login", "Account")); } if (!ModelState.IsValid) { return(View(model)); } string uploadedImageUrl = null; if (model.ImageFile != null) { if (model.ImageFile.ContentLength > 1024 * 1024 * 4) { ViewBag.UploadPostFormVisible = true; AddError("Image file size must not exceed 4MB"); return(View(model)); } else { AmazonBucketClient client = new AmazonBucketClient(); uploadedImageUrl = client.UploadFile(model.ImageFile.InputStream, RandomString()); } } var mentionedUserIds = System.Web.Helpers.Json.Decode <string[]>(model.JsonMentions); var result = await PostsManager.UploadComment(UserToken, new CommentModel { Content = model.CommentContent, ImageUrl = uploadedImageUrl, Mentions = mentionedUserIds }, model.PostId); if (result) { return(RedirectToAction("Index", "Home")); } else { return(ErrorView("Comment was not uploaded")); } }