Beispiel #1
0
        //
        // GET: /Posts/

        public ActionResult Index(int?Id)
        {
            int id = 0;

            if (Id != 0 && Id != null)
            {
                id = (int)Id;

                tbl_Post           p          = PostProvider.GetPost(id);
                List <tbl_Comment> c          = CommentProvider.GetAllCommentByPostId(id);
                PostModel          _PostModel = new PostModel {
                    Id = p.Id, ContentMsg = p.ContentMsg, Title = p.Title, UpdatedBy = p.UpdatedBy
                };
                List <CommentModel> _commentModel = (from temp in c select new CommentModel {
                    Id = temp.Id, CommentText = temp.CommentText, PostId = temp.PostId, CommentedBy = temp.CommentedBy
                }).ToList();
                PostViewModel Model = new PostViewModel();
                Model.Comments = _commentModel;
                Model.Post     = _PostModel;
                return(View(Model));
            }
            else
            {
                return(View());
            }
        }
Beispiel #2
0
        public async Task ThenPostsAreReturned()
        {
            var mockOffers = new Offer[]
            {
                new Offer
                {
                    Articles = new Article[]
                    {
                        new Article
                        {
                            Price            = 19.99m,
                            ShortDescription = "20 x 0,5L (Glas)"
                        },
                        new Article
                        {
                            Price            = 9.99m,
                            ShortDescription = "8 x 0,33L (Glas)"
                        }
                    }
                }
            };
            var reader = new Mock <IOfferReader>();

            reader.Setup(_ => _.ReadAsync()).ReturnsAsync(mockOffers);
            var sut   = new PostProvider(reader.Object);
            var posts = await sut.GetAsync(new PostRequest());

            reader.Verify(_ => _.ReadAsync(), Times.Once);
            posts.Length.Should().Be(2);
        }
Beispiel #3
0
        /// <summary>
        /// Calendar.
        /// </summary>
        /// <returns></returns>
        // GET: /<controller>/
        public async Task <IActionResult> Calendar(int skip, int take)
        {
            // Set page expiration...
            UpdateExpirationToNextDay();

            DateTime dtFilter = DateTime.Now;
//#if DEBUG
//            dtFilter = new DateTime(2016, 01, 01);
//#endif
            // Post metas...
            List <int> catList = _SetViewBagAndGetCats();
            // Post provider...
            PostProvider provider = new PostProvider(AppContext);

            ViewBag.pageMax = await provider?.Count(new Dictionary <string, object>
            {
                { QueryFilter.Categorie, catList },
                { QueryFilter.EndDate, dtFilter }
            });

            ViewBag.Posts = await provider?.Get(new Dictionary <string, object>
            {
                { QueryFilter.Categorie, catList },
                { QueryFilter.EndDate, dtFilter }
            }, skip, take);

            ViewBag.pageSkip = skip;
            ViewBag.pageTake = 20;
            ViewBag.calendar = true;

            //ViewData["Message"] = $"Post: PageId={this.RouteData.Values[CRoute.PageIdTagName]}, PostId={this.RouteData.Values[CRoute.PostIdTagName]}";
            return(View("Index"));
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        /// <summary>
        /// List of post.
        /// </summary>
        /// <returns></returns>
        // GET: /<controller>/
        public async Task <IActionResult> Index(int skip, int take)
        {
            // Set page expiration...
            UpdateExpirationToNextDay();

            // Page metas...
            List <int> catList      = _SetViewBagAndGetCats();
            bool       excludeEvent = (AppContext?.Page?.GetPageFiltering() == PageFiltering.ExcludeEvent);
            // Post provider...
            PostProvider provider = new PostProvider(AppContext);

            ViewBag.pageMax = await provider?.Count(new Dictionary <string, object>
            {
                { QueryFilter.Categorie, catList },
                { QueryFilter.ExcludePostsEvent, excludeEvent },
            });

            ViewBag.Posts = await provider?.Get(new Dictionary <string, object>
            {
                { QueryFilter.Categorie, catList },
                { QueryFilter.ExcludePostsEvent, excludeEvent },
            }, skip, take);

            ViewBag.pageSkip = skip;
            ViewBag.pageTake = 20;

            //ViewData["Message"] = $"Posts: PageId={this.RouteData.Values[CRoute.PageIdTagName]}";
            return(View());
        }
Beispiel #6
0
        public ActionResult Index(int?page)
        {
            List <tbl_Post> lstPost = new List <tbl_Post>();

            lstPost = PostProvider.GetAllPost();
            List <PostModel> Model = (from p in lstPost select new PostModel {
                Id = p.Id, ContentMsg = p.ContentMsg, Title = p.Title, UpdatedBy = p.UpdatedBy
            }).ToList();
            int pageSize           = 3;
            int pageNumber         = (page ?? 1);

            return(View(Model.ToPagedList(pageNumber, pageSize)));
        }
Beispiel #7
0
 public async Task <string> Inscription(int id, [FromBody] List <JsonPostRegistrationField> registrationFields)
 {
     try
     {
         PostProvider provider = new PostProvider(AppContext, _emailSender);
         return(await provider?.Registration(id, registrationFields));
     }
     catch (Exception e)
     {
         AppContext?.Log?.LogError("Exception during post registration - HttpGet:/api/post/inscription/{0}: {1}", id, e.Message);
         return(null);
     }
 }
Beispiel #8
0
 public IActionResult GetPost(Guid id)
 {
     try
     {
         PostProvider post  = _forumsRepository.GetPostById(id);
         var          model = _mapper.Map <PostViewModel>(post);
         return(View("_PostDetails", model));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #9
0
 public IActionResult MoveThread(Guid id)
 {
     try
     {
         PostProvider thread = _forumsRepository.GetPostById(id);
         var          model  = _mapper.Map <MoveThreadViewModel>(thread);
         return(View(model));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #10
0
 public async Task <bool> Delete(int id, int fileId)
 {
     try
     {
         PostProvider provider = new PostProvider(AppContext);
         return((provider == null)
             ? false
             : await provider.DeleteFile(id, fileId));
     }
     catch
     {
         return(false);
     }
 }
 public HttpResponseMessage GetPost(string method, PostModels post)
 {
     try
     {
         using (var provider = new PostProvider())
         {
             return(Request.CreateResponse(HttpStatusCode.OK, provider.getAll()));
         }
     }
     catch (Exception ex)
     {
         result.code    = 0;
         result.message = ex.Message;
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, result));
     }
 }
Beispiel #12
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));
            }
        }
Beispiel #13
0
 public async Task <IActionResult> Upload(int id, string name, int type)
 {
     try
     {
         string       url      = null;
         PostProvider provider = new PostProvider(AppContext, null);
         if (provider == null)
         {
             return(Content("KO:Invalid post provider"));
         }
         else if ((url = await provider.AddFile(id, name, type, Request.Body)) == null)
         {
             return(Content("KO:" + provider.LastError));
         }
         return(Content(url));
     }
     catch (Exception e)
     {
         return(Content("KO:" + e.Message));
     }
 }
Beispiel #14
0
        public BlogPostModule(PostProvider provider)
            : base("/Posts")
        {
            Post["/{start:int}/{finish:int}"] = args =>
            {
                IEnumerable <Post> posts = provider.GetPosts(args.start, args.finish);
                return(Negotiate.WithModel(posts).WithView("BlogPosts"));
            };

            Post["/{PostName}"] = args =>
            {
                Post model = provider.GetPost(args.PostName);
                return(Negotiate
                       .WithModel(model)
                       .WithView("FullPost")
                       .WithHeader("blog-title", model.MetaData.Title));
            };

            Get["/{path}"] = args =>
            {
                return(View["Views/Index.cshtml", (string)args.path]);
            };
        }
 public HttpResponseMessage update([FromBody] PostModels PM)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, new ResultSet()
             {
                 code = 0, message = "Bad Request"
             }));
         }
         using (var provider = new PostProvider())
         {
             return(Request.CreateResponse(HttpStatusCode.OK, provider.updatePost(PM)));
         }
     }
     catch (Exception ex)
     {
         result.code    = 0;
         result.message = ex.Message;
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, result));
     }
 }
Beispiel #16
0
        // GET: Posts
        public ActionResult Index()
        {
            var posts = PostProvider.GetPosts();

            return(View(posts));
        }
Beispiel #17
0
        private async Task _SetViewag()
        {
            IEnumerable <Models.Post> latest = null;
            DateTime dtFilter = DateTime.Now;

//#if DEBUG
//            dtFilter = new DateTime(2016, 01, 01);
//#endif
            // Page metas...
            if (AppContext.Region == null)
            {
                ViewBag.MetaTitle       = "VIE ET PARTAGE";
                ViewBag.MetaDescription = AppContext.Module.DefaultDescription;
                ViewBag.MetaKeywords    = $"{AppContext.Module.DefaultPageKeywords}, {AppContext?.Site?.GetRegionsAsString().ToLower()}";
                ViewBag.MetaRobotsTerms = "index, follow";
                //ViewBag.HideMenu = true;
                ViewBag.HideNavPath  = true;
                ViewBag.ForAllRegion = true;
            }
            else
            {
                ViewBag.MetaTitle       = $"{AppContext?.Region?.StringValue} - VIE ET PARTAGE";
                ViewBag.MetaDescription = $"Vie et partage {AppContext?.Region?.StringValue} - {AppContext.Module.DefaultDescription}";
                ViewBag.MetaKeywords    = $"{AppContext?.Region?.StringValue?.ToLower()}, {AppContext.Module.DefaultPageKeywords}";
                ViewBag.MetaRobotsTerms = "index, follow";
                ViewBag.HideNavPath     = true;
                ViewBag.ForAllRegion    = false;
            }
            // Post provider...
            PostProvider provider = new PostProvider(AppContext);

            // Post data...
            ViewBag.Retaites = await provider?.Get(new Dictionary <string, object>
            {
                { QueryFilter.Categorie, new List <int> {
                      14                                   /*Retraite*/
                  } },
                { QueryFilter.EndDate, dtFilter }
            }, 0, 6);

            ViewBag.Events = await provider?.Get(new Dictionary <string, object>
            {
                { QueryFilter.Categorie, new List <int> {
                      13                                   /*Calendrier*/
                  } },
                { QueryFilter.EndDate, dtFilter }
            }, 0, 6);

            ViewBag.Announcements = latest = await provider?.Get(new Dictionary <string, object>
            {
                { QueryFilter.Categorie, new List <int> {
                      15                                   /*Annonces*/
                  } },
            }, 0, 20);

            //int nbLatest = ((latest?.Count() ?? 0) == 0) ? 11 : 6;
            ViewBag.Latests = await provider?.Get(new Dictionary <string, object>
            {
                { QueryFilter.ExcludePostsEvent, true },
                { $"{QueryFilter.Categorie}!", new List <int> {
                      13 /*Retraite*/, 14 /*Calendrier*/, 15                                       /*Annonces*/
                  } },
            }, 0, 6 /*nbLatest*/);
        }
Beispiel #18
0
        public async Task <IActionResult> Register(List <JsonPostRegistrationField> registrationFields)
        {
            bool         isError  = false;
            PostProvider provider = new PostProvider(AppContext, _emailSender);

            // Set page metas...
            _SetPageMetas();
            ViewBag.MetaRobotsTerms = "noindex, nofollow";
            // Checking for the model...
            if ((registrationFields?.Count ?? 0) == 0)
            {
                ViewBag.RegistrationMessage = "Une erreur s'est produite veuillez réessayer ultérieurement!";
                return(Register());
            }
            //ModelState.IsValid
            // Checking model contains...
            foreach (JsonPostRegistrationField field in registrationFields)
            {
                // Init...
                field.IsError  = false;
                field.IsError2 = false;
                // Checking...
                if (field.Type == 1)
                {
                    // Text area...
                    if (string.IsNullOrEmpty(field.Value) == true)
                    {
                        isError       = true;
                        field.IsError = true;
                    }
                }
                else if (field.Type == 2)
                {
                    // Oui\non...
                    if (string.IsNullOrEmpty(field.Value) == true)
                    {
                        isError       = true;
                        field.IsError = true;
                    }
                }
                else if (field.Type == 3)
                {
                    // Oui\non - Precisez...
                    if (string.IsNullOrEmpty(field.Value) == true)
                    {
                        isError       = true;
                        field.IsError = true;
                    }
                    else if (field.Value == "Oui" &&
                             string.IsNullOrEmpty(field.Value2) == true)
                    {
                        isError        = true;
                        field.IsError2 = true;
                    }
                }
                if (field.Type == 4 || field.Type == 5)
                {
                    // Choix 1...
                    if (string.IsNullOrEmpty(field.Value) == true)
                    {
                        isError       = true;
                        field.IsError = true;
                    }
                }
                if (field.Type == 5)
                {
                    // Choix 2...
                    if (string.IsNullOrEmpty(field.Value2) == true)
                    {
                        isError        = true;
                        field.IsError2 = true;
                    }
                }
            }
            // Process the registration...
            if (isError == false &&
                string.IsNullOrEmpty(ViewBag.RegistrationResult = await(provider?.Registration(AppContext?.Post, registrationFields) ?? null)) == false)
            {
                // Registration succedded...
                return(View(null));
            }
            // Provide the error...
            if (isError == true)
            {
                ViewBag.RegistrationMessage = "Veuillez remplir tous les champs obligatoires!";
            }
            else if (string.IsNullOrEmpty(ViewBag.RegistrationResult) == true)
            {
                ViewBag.RegistrationMessage = "Une erreur s'est produite veuillez réessayer ultérieurement!";
            }
            // Update the registration data...
            List <JsonPostRegistrationField> dbRegistrationFields = _GetRegistrationFiedl();

            for (int i = 0; i < dbRegistrationFields?.Count; i++)
            {
                try
                {
                    dbRegistrationFields[i].Value    = registrationFields[i].Value;
                    dbRegistrationFields[i].Value2   = registrationFields[i].Value2;
                    dbRegistrationFields[i].IsError  = registrationFields[i].IsError;
                    dbRegistrationFields[i].IsError2 = registrationFields[i].IsError2;
                }
                catch { }
            }
            return(View(dbRegistrationFields));
        }
Beispiel #19
0
        private static void Main(string[] args)
        {
            /* FOR ALL EXERCISES:
             *
             * 1) All output needs to be sent to the console.
             * 2) Each exercise must be separated by a System.Console.ReadLine(); statement.
             * 3) All provided code must be used as is, unless otherwise explicitly stated.
             * 4) You may use the "MyCode" folder in DevTest.Library or within this class for any code you develop
             *    (unless otherwise specified).
             */

            /* Exercise 1:
             *
             * Implement the IsPalindrome method in the MyPalindromeChecker class.
             * Use the WordProvider to retrieve a randomized list of words, which may or may not be palindromes.
             * Check each word returned by the WordProvider and output the word and whether or not is a palindrome. A
             * word may contain one or more whitespaces.
             *
             * Example output:
             * Word: radar; IsPalindrome: true
             * Word: chicken; IsPalindrome: false
             */
            var words = WordProvider.GetWords();

            //implement exercise 1

            System.Console.WriteLine("End of exercise 1.");
            System.Console.ReadLine();

            /* Exercise 2:
             *
             * Implement a paging algorithm using the given WordProvider. The provider will output a random number
             * of strings, in order. The list will include a minimum of 10 strings. A single page will be between 3 and 6
             * (inclusive) items. (represented by the pageSize variable). Your output should page all the way to the end
             * of the list, showing every item in the list, and include the page number. Each page should be separated
             * by a System.Console.ReadLine(); statement.
             *
             * Example output (pageSize = 5):
             *
             * Page #1
             * 1. word1
             * 2. word2
             * 3. word3
             * 4. word4
             * 5. word5
             *
             * Page #2
             * 6. word6
             * 7. word7
             * 8. word8
             * 9. word9
             * 10. word10
             */
            var wordList = WordProvider.GetWordList();
            var pageSize = new Random().Next(3, 6);

            //implement exercise 2

            System.Console.WriteLine("End of exercise 2.");
            System.Console.ReadLine();

            /* Exercise 3:
             *
             * Given the posts supplied by the PostProvider, do the following:
             *
             * 1) Display a list of all posts that contain the following information:
             *      - User who made the post
             *      - The textual content of the post
             *      - The total number of comments
             *      - The user names of each commenter, separated by commas
             * 2) Display a list of users that have liked a post. Include the post content and a comma
             *    separated list of the user's names.
             *
             *    Example output:
             *    post1: sasha, brittany, eric
             *    post4: amber
             *    post8: monica
             *
             * 3) Display a list of comments, grouped by commenter, made by persons older than 25 (as
             *    of "today"). Include the commenter's name.
             *
             *    Example output:
             *    steve
             *    -----
             *    Every strike brings me closer to the next home run. –Babe Ruth
             *    Everything you’ve ever wanted is on the other side of fear. –George Addair
             *
             *    jeremy
             *    ------
             *    Challenges are what make life interesting and overcoming them is what makes life meaningful. –Joshua J. Marine
             *    There are no traffic jams along the extra mile. –Roger Staubach
             *    It’s your place in the world; it’s your life. Go on and do all you can with it, and make it the life you want to live. –Mae Jemison
             */
            var posts   = PostProvider.GetPosts();
            var persons = PostProvider.GetPersons();

            //implement exercise 3.1

            System.Console.WriteLine("End of exercise 3.1.");
            System.Console.ReadLine();

            //implement exercise 3.2

            System.Console.WriteLine("End of exercise 3.2.");
            System.Console.ReadLine();

            //implement exercise 3.3
            System.Console.WriteLine("End of exercise 3.3.");
            System.Console.ReadLine();
        }
Beispiel #20
0
        public async Task <JsonListPost> Get([FromBody] JsonListSettings settings)
        {
            try
            {
                // Initialisation...
                Dictionary <string, string> defaultFilters = settings?.DefaultFilters;
                if (settings == null || settings.Filters == null)
                {
                    settings = new JsonListSettings()
                    {
                        Count   = 0,
                        Skip    = 0,
                        Take    = 20,
                        Filters = new Dictionary <string, string>()
                        {
                            { QueryFilter.MineToo, "true" }
                        }
                    };
                    if ((AppContext.User?.HasRole(ClaimValueRole.Administrator) ?? false) == true ||
                        (AppContext.User?.HasRole(ClaimValueRole.Publicator) ?? false) == true)
                    {
                        settings.Filters.Add(QueryFilter.State, "-1");
                    }
                    else
                    {
                        settings.Filters.Add(QueryFilter.State, "1");
                    }
                    if (settings == null || settings.Filters == null)
                    {
                        _Log.LogCritical("Not enough memory to allocate a new JsonListSettings!");
                        return(null);
                    }
                }
                if (defaultFilters != null)
                {
                    foreach (KeyValuePair <string, string> kp in defaultFilters)
                    {
                        settings.Filters.Add(kp.Key, kp.Value);
                    }
                }
                // By default: Always add childs items of the categories...
                if (settings.Filters.ContainsKey(QueryFilter.ShowChildsCategoriesPosts) == false)
                {
                    settings.Filters.Add(QueryFilter.ShowChildsCategoriesPosts, "true");
                }
                // Get posts based on filter...
                PostProvider provider = new PostProvider(AppContext);
                Dictionary <string, object> filters = provider?.ConvertFilter(settings.Filters);
                IEnumerable <Post>          posts   = await provider?.Get(filters, settings.Skip, settings.Take);

                JsonListPost list = new JsonListPost(settings, posts?.Select(p => new JsonPost(AppContext, p)));
                if (settings.Skip == 0 && settings.Count == 0 &&
                    list != null)
                {
                    // Get posts total count...
                    list.Settings.Count = await provider?.Count(filters);
                }
                // Clean settings...
                if (defaultFilters != null)
                {
                    foreach (KeyValuePair <string, string> kp in defaultFilters)
                    {
                        settings.Filters.Remove(kp.Key);
                    }
                }
                return(list);
            }
            catch (Exception e)
            {
                AppContext?.Log?.LogError("Exception getting posts - HttpPost:/api/post/list: {0}", e.Message);
                return(null);
            }
        }