public static Comments ParseCommentModelToEntity(CommentModel model) { var entity = new Comments(); entity.Id = model.Id; entity.CommentText = model.CommentText; entity.CommentDatetime = model.CommentDatetime; entity.UserId = model.UserId; entity.WallId = model.WallId; return entity; }
public IHttpActionResult PostComments(Comments comments) { if (!ModelState.IsValid) { return BadRequest(ModelState); } comments.User = db.Users.Where(c => c.Id == comments.UserId).SingleOrDefault(); db.Comments.Add(comments); db.SaveChanges(); var temp = new CommentModel(); temp = ModelFactory.ParseCommentEntityToModel(comments); return CreatedAtRoute("DefaultApi", new { id = comments.Id }, temp); }
public static CommentModel ParseCommentEntityToModel(Comments u) { var model = new CommentModel(); model.Id = u.Id; model.CommentText = u.CommentText; model.CommentDatetime = u.CommentDatetime; model.UserId = u.UserId; model.UserFirstName = u.User.FirstName; model.UserLastName = u.User.LastName; model.WallId = u.WallId; return model; }