Пример #1
0
        public async Task <JsonPost> Get(int id)
        {
            try
            {
                JsonPost jsnPost = null;
                // Get and return the post...
                if (id == 0)
                {
                    // Call for adding a new post...
                    jsnPost             = new JsonPost(AppContext, null, true);
                    jsnPost.Title       = "Votre titre ici...";
                    jsnPost.TextContain = "Votre texte la...";
                }
                else
                {
                    PostProvider provider = new PostProvider(AppContext);
                    Post         post     = await provider?.Get(id);

                    jsnPost = new JsonPost(AppContext, post, true);
                }
                return(jsnPost);
            }
            catch (Exception e)
            {
                AppContext?.Log?.LogError("Exception getting post - HttpGet:/api/post/{0}: {1}", id, e.Message);
                return(null);
            }
        }
Пример #2
0
        public async Task <JsonPost> Post(int type, [FromBody] JsonPost post)
        {
            try
            {
                if (post != null)
                {
                    Post         postEdited = null;
                    PostProvider provider   = new PostProvider(AppContext);

                    // Update the post...
                    if (type == 1)
                    {
                        // Update post title and text...
                        postEdited = await provider?.Update(post.Id, post.Title, post.TextContain);
                    }
                    else if (type == 2)
                    {
                        // Update post start\end date and registration...
                        postEdited = await provider?.Update(post.Id, post.StartDateString, post.EndDateString,
                                                            post.ClaimRegistration, post.RegistrationWebConfirmation, post.RegistrationEmailConfirmation,
                                                            post.RegistrationFields /*RegistrationFieldsToPartialClaims()*/);
                    }
                    else if (type == 3)
                    {
                        // Update post settings...
                        postEdited = await provider?.Update(post.Id, post.State,
                                                            post.PostRegions.ToIdArray(), post.PostCategorys.ToIdArray(),
                                                            post.PostTags.ToIdArray(), post.PostGroups.ToIdArray());
                    }

                    // The result...
                    post = (postEdited == null)
                        ? new JsonPost(provider?.LastError)
                        : new JsonPost(AppContext, postEdited, true);
                }
                //Thread.Sleep(5 * 1000);
                return(post);
            }
            catch (Exception e)
            {
                AppContext?.Log?.LogError("Exception updating post - HttpPost:/api/post(type={0}, post={1}): {2}", type, post?.Id ?? 0, e.Message);
                return(new JsonPost(UserMessage.UnexpectedError));
            }
        }