Server.Models.Post.createPost C# (CSharp) Méthode

createPost() public méthode

public createPost ( string PostTitle, string PostText ) : string
PostTitle string
PostText string
Résultat string
        public string createPost(string PostTitle, string PostText)
        {
            try
            {
                using (var ctx = new PostContext())
                {
                    //if (!ctx.Database.Exists())
                    //{
                    //    ((IObjectContextAdapter)ctx).ObjectContext.CreateDatabase();
                    //}
                    Post post = new Post()
                    {

                        PostTitle = PostTitle,
                        PostText = PostText,
                        PostDate = DateTime.Now,
                        PostDeletedDate = null
                    };

                    ctx.Posts.Add(post);
                    ctx.SaveChanges();
                }
                return "ok";
            }
            catch (Exception)
            {
                return "fail";
            }
        }