public QuestionViewModel(Question question) { this.Id = question.Id; this.QuestionContent = question.QuestionContent; this.AnswerContent = question.AnswerContent; this.TimePosted = question.TimePosted; this.TimeAnswered = question.TimeAnswered; this.CouponId = question.CouponId; this.Coupon = question.Coupon; this.BuyerName = question.BuyerName; this.SellerName = question.SellerName; this.BuyerAvatar = question.BuyerAvatar; this.SellerAvatar = question.SellerAvatar; }
public IHttpActionResult CreateQuestion(Question question) { var userId = this.User.Identity.GetUserId(); var user = db.Users.Find(userId); question.BuyerName = user.FirstName; question.BuyerAvatar = user.AvatarUrl; question.TimePosted = DateTime.Now; if (ModelState.IsValid) { db.Questions.Add(question); db.SaveChanges(); return Ok(question); } return BadRequest(ModelState); }