Ejemplo n.º 1
0
        public ActionResult Create(PostModel model)
        {
            string returnUrl = HttpContext.Request.Params["returnUrl"].Length > 0 ? HttpContext.Request.Params["returnUrl"] : HttpContext.Request.UrlReferrer.ToString();

            if(ModelState.IsValid)
            {
                try
                {
                    Entities dbContext = new Entities();

                    Models.Object obj = new Models.Object();
                    obj.EntityName = "Post";
                    dbContext.Objects.AddObject(obj);
                    dbContext.SaveChanges();

                    Post post = new Post();

                    post.Id = obj.Id;
                    post.UserId = new Guid(UserHelper.getLoggedInUserId());
                    post.PersonId = new Guid(HttpContext.Request.Params["personId"].Length > 0 ? HttpContext.Request.Params["personId"] : UserHelper.getLoggedInUserId());
                    post.Content = model.Content;
                    post.CreatedAt = DateTime.Now;
                    post.UpdatedAt = DateTime.Now;

                    dbContext.Posts.AddObject(post);
                    dbContext.SaveChanges();

                    return Redirect(returnUrl);
                }catch(Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            return View(model);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Posts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPosts(Post post)
 {
     base.AddObject("Posts", post);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new Post object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="personId">Initial value of the PersonId property.</param>
 /// <param name="createdAt">Initial value of the CreatedAt property.</param>
 public static Post CreatePost(global::System.Int32 id, global::System.Guid userId, global::System.Guid personId, global::System.DateTime createdAt)
 {
     Post post = new Post();
     post.Id = id;
     post.UserId = userId;
     post.PersonId = personId;
     post.CreatedAt = createdAt;
     return post;
 }