コード例 #1
0
        public void When_LoadNewStoriesCommand_Then_LoadNewStoriesExecute()
        {
            IList <int> storyIds = new List <int> {
                2, 3, 4, 5, 6, 7, 8, 9, 10, 11
            };

            hackerNewsServiceMock
            .Setup(x => x.NewStories())
            .Returns(Task.FromResult(storyIds));

            hackerNewsServiceMock
            .Setup(x => x.Story(It.IsAny <long>()))
            .Returns(Task.FromResult(new Story {
                Id = It.IsAny <long>()
            }));

            var storyViewModel = new StoriesViewModel(navigationServiceMock.Object, hackerNewsServiceMock.Object);

            storyViewModel.LoadStoriesCommand.Execute(null);

            Check.That(storyViewModel.Stories).IsNotNull();
            Check.That(storyViewModel.Stories.Count).IsEqualTo(10);
            hackerNewsServiceMock.Verify(x => x.NewStories(), Times.Once());
            hackerNewsServiceMock.Verify(x => x.Story(It.IsAny <long>()), Times.Exactly(10));
        }
コード例 #2
0
        public ActionResult Story()
        {
            var  db = new CareersDataContext();
            var  storiesViewModel = new StoriesViewModel();
            long inputId          = Int64.Parse(RouteData.Values["Id"].ToString());
            var  story            = db.Stories.Where(x => x.Id == inputId).ToArray();

            if (RouteData.Values["slug"] == null)
            {
                return(Redirect(@"~\" + "careers/" + story[0].CareerName + "/" + RouteData.Values["Id"].ToString() + "/" + getSlug(Int64.Parse(RouteData.Values["Id"].ToString()))));
            }

            //sanitize url for careername (again), id, AND slug.
            string inputUrlParam;
            string cleanUrlParam;

            inputUrlParam = RouteData.Values["careerName"].ToString();
            cleanUrlParam = URLFriendly(inputUrlParam);

            if (!inputUrlParam.Equals(cleanUrlParam))
            {//use StringBuilder here for optimization
                return(Redirect(@"~\" + "careers/" + cleanUrlParam + "/" + RouteData.Values["Id"].ToString() + "/"
                                + RouteData.Values["slug"].ToString()));
            }

            if (!RouteData.Values["slug"].ToString().Equals(getSlug(Int64.Parse(RouteData.Values["Id"].ToString()))))
            {
                return(Redirect(@"~\" + "careers/" + RouteData.Values["careerName"].ToString() + "/" + RouteData.Values["Id"].ToString() + "/" + getSlug(Int64.Parse(RouteData.Values["Id"].ToString()))));
            }

            if (story.Length < 1)
            {//wrong id
                return(Redirect(@"~\" + "careers/" + RouteData.Values["careerName"].ToString()));
            }

            storiesViewModel.CareerName       = story[0].CareerName;
            storiesViewModel.StarCount        = story[0].StarCount;
            storiesViewModel.PostCount        = story[0].PostCount;
            storiesViewModel.FunnyCount       = story[0].FunnyCount;
            storiesViewModel.InformativeCount = story[0].InformativeCount;
            storiesViewModel.Username         = story[0].Username;
            storiesViewModel.Story            = story[0].Story;
            storiesViewModel.Title            = story[0].Title;
            storiesViewModel.Education        = story[0].Education;
            storiesViewModel.Company          = story[0].Company;
            storiesViewModel.Salary           = story[0].Salary;
            storiesViewModel.Location         = story[0].Location;
            storiesViewModel.PostDate         = story[0].PostDate;

            ///////////////////////////////

            /*Posts and Replies: use the inputId variable to find corresponding posts and replies.  Add them to ViewBag variables and display them
             * in the View.
             * */
            var PostsList = db.Posts.Where(u => u.IsActive == 1 && u.StoryId == inputId).OrderBy(u => u.PostDate).ToList();

            ViewBag.PostsList = PostsList;
            ///////////////////////////////
            return(View(storiesViewModel));
        }
コード例 #3
0
        private async Task <StoriesViewModel> GetAll(Expression <Func <Story, double> > sort, int page, int pageSize, Guid?userId)
        {
            var model = new StoriesViewModel()
            {
                CurrentPage = page, PageSize = pageSize
            };

            var stories = await StoriesDbContext.Stories.Include(s => s.User)
                          .Include(s => s.Comments)
                          .Include(s => s.Score)
                          .OrderByDescending(s => s.Score != null)
                          .ThenBy(sort)
                          .ThenByDescending(s => s.CreatedDate)
                          .Skip(page * pageSize)
                          .Take(pageSize)
                          .ToListAsync();

            List <int> upvotedStoryIds = new List <int>();

            if (userId != null)
            {
                upvotedStoryIds = await StoriesDbContext.Votes.Where(v => stories.Any(s => s.Id == v.StoryId) && v.UserId == userId).Select(v => v.StoryId.Value).ToListAsync();
            }

            foreach (var story in stories)
            {
                var userUpvoted = upvotedStoryIds.Any(id => id == story.Id);
                var hashId      = new Hashids(minHashLength: 5).Encode(story.Id);

                model.Stories.Add(MapToStorySummaryViewModel(story, hashId, userId, userUpvoted));
            }

            return(model);
        }
コード例 #4
0
        public JsonResult UploadFiles(StoriesViewModel ViewModel)
        {
            var profile = Request.Files;

            string imgname   = string.Empty;
            string ImageName = string.Empty;

            //Following code will check that image is there
            //If it will Upload or else it will use Default Image

            //if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
            //{
            //    var logo = System.Web.HttpContext.Current.Request.Files["file"];
            //    if (logo.ContentLength > 0)
            //    {
            //        var profileName = Path.GetFileName(logo.FileName);
            //        var ext = Path.GetExtension(logo.FileName);

            //        ImageName = profileName;
            //        var comPath = Server.MapPath("/Images/") + ImageName;

            //        logo.SaveAs(comPath);
            //        userDetail.Profile = comPath;
            //    }

            //}
            //else
            //    userDetail.Profile = Server.MapPath("/Images/") + "profile.jpg";

            int response = 1;

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public StoriesViewModel GetStoriesModel()
        {
            var model = new StoriesViewModel();

            model.MaxItemsToShow  = 3;
            model.ShowFullStories = false;
            model.Stories         = _dataContext.Stories.ToList();
            return(model);
        }
コード例 #6
0
        public async Task <IActionResult> OnGet()
        {
            ViewModel = new StoriesViewModel();
            ViewModel.Anouncements = new List <Anouncement>();

            ViewModel.Anouncements = await _data.GetAnouncementsAsync();

            return(Page());
        }
コード例 #7
0
        public async Task <IActionResult> OnGet()
        {
            ViewModel = new StoriesViewModel
            {
                Anouncements = await _storyData.GetAnouncementsAsync()
            };

            return(Page());
        }
コード例 #8
0
        public void When_GoToStoryCommand_Then_GoToStoryExecute()
        {
            var storyViewModel = new StoriesViewModel(navigationServiceMock.Object, hackerNewsServiceMock.Object);

            storyViewModel.GoToStoryCommand.Execute(new Story {
                Id = 1
            });

            navigationServiceMock.Verify(x => x.PushToAsync <StoryViewModel>((long)1), Times.Once());
        }
コード例 #9
0
 // initialize the constructor
 public StoriesController(ApplicationDbContext db, HostingEnvironment hostingEnvironment)
 {
     _db = db;
     _hostingEnvironment = hostingEnvironment;
     StoriesVM           = new StoriesViewModel()
     {
         StoryTypes  = _db.StoryTypes.ToList(),
         SpecialTags = _db.SpecialTags.ToList(),
         PrivacyTags = _db.PrivacyTags.ToList(),
         Stories     = new Stories()
     };
 }
コード例 #10
0
 public StoriesController(ApplicationDbContext db, UserManager <IdentityUser> userManager)
 {
     _db          = db;
     _userManager = userManager;
     StoriesVM    = new StoriesViewModel()
     {
         StoryTypes  = _db.StoryTypes.ToList(),
         SpecialTags = _db.SpecialTags.ToList(),
         PrivacyTags = _db.PrivacyTags.ToList(),
         Stories     = new Stories(),
         StoryBlocks = new List <StoryBlocks>(),
         Comments    = new List <Comments>()
     };
 }
コード例 #11
0
 public ActionResult AddCampaignTarget(int Id = 0)
 {
     try
     {
         StoriesViewModel Model = new StoriesViewModel();
         if (Id > 0)
         {
             Model = IService.GetStorie(Id);
         }
         return(View(Model));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #12
0
        public ActionResult Index()
        {
            var db      = new ApplicationDbContext();
            var stories = new StoriesViewModel();

            stories.top3 = db.Stories.OrderByDescending(x => x.Score)
                           .Take(3)
                           .Include(s => s.Author)
                           .ToList();

            stories.last10 = db.Stories.OrderByDescending(x => x.Date)
                             .Take(10)
                             .ToList();

            return(View(stories));
        }
コード例 #13
0
        // initialize the constructor
        public StoriesListController(ApplicationDbContext db, UserManager <IdentityUser> userManager, HostingEnvironment hostingEnvironment)
        {
            _db                 = db;
            _userManager        = userManager;
            _hostingEnvironment = hostingEnvironment;
            ImageFormat         = new List <string>(new string[] { ".jpg", ".jpeg", ".png", ".bmp", ".gif" });

            StoriesVM = new StoriesViewModel()
            {
                StoryTypes  = _db.StoryTypes.ToList(),
                SpecialTags = _db.SpecialTags.ToList(),
                PrivacyTags = _db.PrivacyTags.ToList(),
                Stories     = new Stories(),
                StoryBlocks = new List <StoryBlocks>(),
                Comments    = new List <Comments>()
            };
        }
コード例 #14
0
        public ActionResult AddCampaign(CampaignMainViewModel ViewModel)
        {
            try
            {
                var Id = IService.CreateCampaign(ViewModel);
                if (Id > 0)
                {
                    StoriesViewModel Model = new StoriesViewModel();
                    Model = IService.GetStorieDetails(Id);

                    return(View("AddBeneficiary", Model));
                }
                else
                {
                    return(View(ViewModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #15
0
        public ActionResult AddCampaignTarget(StoriesViewModel ViewModel)
        {
            try
            {
                ViewModel.CampaignTarget.storyId = ViewModel.Id;
                var Id = IService.CreateTarget(ViewModel.CampaignTarget);
                if (Id > 0)
                {
                    StoriesViewModel Model = new StoriesViewModel();
                    Model = IService.GetStorieDetails(Id);

                    return(View("AddCampaignDescription", Model));
                }
                else
                {
                    return(View(ViewModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #16
0
        public static List <StoriesViewModel> Get(List <Stories> stories)
        {
            var listOfStories = new List <StoriesViewModel>();

            foreach (var item in stories)
            {
                var svm = new StoriesViewModel()
                {
                    StoryGuid       = item.StoryGuid,
                    EastStoryGuid   = item.EastStoryGuid,
                    WestStoryGuid   = item.WestStoryGuid,
                    NorthStoryGuid  = item.NorthStoryGuid,
                    LastActivity    = item.LastActivity,
                    NumberOfStories = item.NumberOfStories,
                    SouthStoryGuid  = item.SouthStoryGuid,
                    StoryText       = item.StoryText,
                    Title           = item.StoryText
                };

                listOfStories.Add(svm);
            }

            return(listOfStories);
        }
コード例 #17
0
 public ChangeContextCommand(StoriesViewModel storiesViewModel)
 {
     StoriesViewModel = storiesViewModel;
 }
コード例 #18
0
ファイル: StoriesController.cs プロジェクト: nordsoyv/HourReg
 //
 // GET: /Stories/AddTasks
 public ActionResult AddTasks(int id)
 {
     Story s = new Story();
     StoriesViewModel m = new StoriesViewModel(s);
     return View(m);
 }
コード例 #19
0
ファイル: StoriesController.cs プロジェクト: nordsoyv/HourReg
 //
 // GET: /Stories/Edit/5
 public ActionResult Edit(int id)
 {
     Story s = repo.GetStory(id);
     StoriesViewModel m = new StoriesViewModel(s);
     return View(m);
 }
コード例 #20
0
        //public ActionResult AddStories([Bind(Exclude = "File1,File2,File3,File4,File5")]StoriesViewModel ViewModel)//, HttpPostedFileBase File1)//, HttpPostedFileBase File2, HttpPostedFileBase File3, HttpPostedFileBase File4, HttpPostedFileBase File5)
        public ActionResult AddStories([Bind(Exclude = "File1,File2,File3,File4,File5")] StoriesViewModel ViewModel)
        {
            try
            {
                Files fileModel = new Files();
                ViewModel.Files = new List <Files>();
                if (Request != null)
                {
                    if (Request.Files.Count > 0)
                    {
                        var file1 = Request.Files[0];

                        if (file1 != null && file1.ContentLength > 0)
                        {
                            fileModel          = new Files();
                            fileModel.File     = Bytes(file1); // file1 to store image in binary formate
                            fileModel.FileName = System.IO.Path.GetFileName(file1.FileName);
                            ViewModel.Files.Add(fileModel);
                        }
                    }
                    if (Request.Files.Count > 1)
                    {
                        var file2 = Request.Files[1];

                        if (file2 != null && file2.ContentLength > 0)
                        {
                            fileModel          = new Files();
                            fileModel.File     = Bytes(file2); // file1 to store image in binary formate
                            fileModel.FileName = System.IO.Path.GetFileName(file2.FileName);
                            ViewModel.Files.Add(fileModel);
                        }
                    }
                    if (Request.Files.Count > 2)
                    {
                        var file3 = Request.Files[2];

                        if (file3 != null && file3.ContentLength > 0)
                        {
                            fileModel          = new Files();
                            fileModel.File     = Bytes(file3); // file1 to store image in binary formate
                            fileModel.FileName = System.IO.Path.GetFileName(file3.FileName);
                            ViewModel.Files.Add(fileModel);
                        }
                    }
                    if (Request.Files.Count > 3)
                    {
                        var file4 = Request.Files[3];

                        if (file4 != null && file4.ContentLength > 0)
                        {
                            fileModel          = new Files();
                            fileModel.File     = Bytes(file4); // file1 to store image in binary formate
                            fileModel.FileName = System.IO.Path.GetFileName(file4.FileName);
                            ViewModel.Files.Add(fileModel);
                        }
                    }
                    if (Request.Files.Count > 4)
                    {
                        var file5 = Request.Files[4];

                        if (file5 != null && file5.ContentLength > 0)
                        {
                            fileModel          = new Files();
                            fileModel.File     = Bytes(file5); // file1 to store image in binary formate
                            fileModel.FileName = System.IO.Path.GetFileName(file5.FileName);
                            ViewModel.Files.Add(fileModel);
                        }
                    }
                }
                var res = IService.CreateStory(ViewModel);
                if (res)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(ViewModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #21
0
 public GetStoriesCommand(StoriesViewModel storiesViewModel)
 {
     StoriesViewModel = storiesViewModel;
 }
コード例 #22
0
 public GoToUrlCommand(StoriesViewModel storiesViewModel)
 {
     StoriesViewModel = storiesViewModel;
 }
コード例 #23
0
ファイル: StoriesController.cs プロジェクト: nordsoyv/HourReg
 //
 // GET: /Stories/Create
 public ActionResult Create()
 {
     Story s = new Story();
     StoriesViewModel m = new StoriesViewModel(s);
     return View(m);
 }