Exemple #1
0
        public async Task AddWishAsync_Returns_Created_With_The_New_Wish()
        {
            var reqModel = new WishViewModel
            {
                Name   = "a thing",
                Query  = "a.thing",
                Active = false
            };
            var req = TestHelper.CreateHttpRequest(reqModel);

            _authService.Setup(s => s.IsAuthenticated(req)).ReturnsAsync(true);
            _table.SetupOperation(TableOperationType.Insert, () => new Wish
            {
                Name   = reqModel.Name,
                Query  = reqModel.Query,
                Active = reqModel.Active.Value
            });

            var resp = await _function.AddWishAsync(req, _table.Object, _log.Object);

            _table.VerifyOperation(TableOperationType.Insert);
            var cr    = Assert.IsType <CreatedResult>(resp);
            var model = Assert.IsType <WishViewModel>(cr.Value);

            Assert.NotNull(model.Id);
            Assert.Equal(reqModel.Name, model.Name);
            Assert.Equal(reqModel.Query, model.Query);
            Assert.Equal(reqModel.Active, model.Active);
        }
Exemple #2
0
        /// <summary>
        /// 收藏列表信息
        /// </summary>
        /// <param name="index">页索引</param>
        /// <param name="size">显示个数</param>
        /// <returns></returns>
        public async Task <IActionResult> WishList(int index = 1, int size = 5)
        {
            WishViewModel wishViewModel = new WishViewModel();
            var           response      = await httpClient.GetAsync("/api/cates/0");

            ViewBag.Index = index;
            if (response.IsSuccessStatusCode)
            {
                wishViewModel.Product_CategoryDtos = await response.Content.ReadAsJsonAsync <List <Product_CategoryDto> >();
            }
            var token = Request.Cookies["token"];

            if (token == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (token == "null")
            {
                return(RedirectToAction("Login", "Account"));
            }
            httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            var wishResponse = await httpClient.GetAsync($"/api/wishs?index={index}&size={size}");

            if (wishResponse.IsSuccessStatusCode)
            {
                wishViewModel.PageList = await wishResponse.Content.ReadAsJsonAsync <PageList <WishDto> >();
            }

            else
            {
                return(RedirectToAction("Login", "Account"));
            }
            return(View(wishViewModel));
        }
 public static Wish ToDomainModel(this WishViewModel wish) => new Wish
 {
     Active         = wish.Active.HasValue ? wish.Active.Value : true,
     Name           = wish.Name,
     Query          = wish.Query,
     LastSearchDate = DateTime.UtcNow.AddDays(-6)
 };
        private async Task <WishViewModel> CreateViewModelFromWish(Wish wish)
        {
            var viewModel = new WishViewModel();

            viewModel.Id      = wish.Id;
            viewModel.BuyerId = wish.BuyerId;
            viewModel.Items   = await GetWishItems(wish.Items);;
            return(viewModel);
        }
Exemple #5
0
        public ActionResult Index()
        {
            string text = "hello world".ToTitleCase();


            WishViewModel model = _adapter.GetRandomWish();

            return(View(model));
        }
        public void Validate_Fails_When_The_Name_Is_Missing()
        {
            var model = new WishViewModel
            {
                Query = "guess.whats.missing"
            };

            var results = _validator.Validate(model);

            Assert.False(results.IsValid);
            Assert.Contains(results.Errors, e => e.ErrorMessage == "You have to give your wish a name!");
        }
        public IActionResult Put([FromBody] WishViewModel wishViewModel)
        {
            if (!ModelState.IsValid)
            {
                NotifyModelStateErrors();
                return(Response(wishViewModel));
            }

            _wishAppService.Update(wishViewModel);

            return(Response(wishViewModel));
        }
        public void Validate_Fails_When_The_Query_Is_Missing()
        {
            var model = new WishViewModel
            {
                Name = "What Am I Searching For"
            };

            var results = _validator.Validate(model);

            Assert.False(results.IsValid);
            Assert.Contains(results.Errors, e => e.ErrorMessage == "You have to specify a query to search for!");
        }
        public void Validate_Succeeds()
        {
            var model = new WishViewModel
            {
                Name  = "New Wish",
                Query = "new.wish"
            };

            var results = _validator.Validate(model);

            Assert.True(results.IsValid);
            Assert.Empty(results.Errors);
        }
Exemple #10
0
 public ActionResult <string> UpdateBox([FromBody] WishViewModel wish)
 {
     try
     {
         _logger.LogInformation("Received patch Box request");
         _boxServices.UpdateBox(_mapper.Map <Wish>(wish));
         return(Ok("OK"));
     }
     catch (Exception exception)
     {
         _logger.LogError(exception, exception.Message);
         return(new StatusCodeResult(500));
     }
 }
Exemple #11
0
 public ActionResult <string> InsertNewBag([FromBody] WishViewModel wish)
 {
     try
     {
         _logger.LogInformation("Received post Bag request");
         _bagServices.InsertNewBag(_mapper.Map <Wish>(wish));
         return(Ok("success"));
     }
     catch (Exception exception)
     {
         _logger.LogError(exception, exception.Message);
         return(new StatusCodeResult(500));
     }
 }
 public ActionResult <string> InsertNewContent([FromBody] WishViewModel wish, [FromRoute] int boxid)
 {
     try
     {
         _logger.LogInformation("Received post Box Content request");
         _boxcontentServices.InsertNewContent(_mapper.Map <Wish>(wish), boxid);
         return(Ok("success"));
     }
     catch (Exception exception)
     {
         _logger.LogError(exception, exception.Message);
         return(new StatusCodeResult(500));
     }
 }
 public ActionResult <string> NewExchange([FromRoute] int boxid, [FromBody] WishViewModel wish)
 {
     try
     {
         _logger.LogInformation("Received post Exchange request");
         _exchangeServices.NewExchange(_mapper.Map <Wish>(wish), boxid);
         return(Ok("success"));
     }
     catch (Exception exception)
     {
         _logger.LogError(exception, exception.Message);
         return(new StatusCodeResult(500));
     }
 }
Exemple #14
0
 private Wish ToWish(WishViewModel model)
 {
     return(new Wish
     {
         Id = model.Id,
         Title = model.Title,
         SubTitle = model.SubTitle,
         Description = model.Description,
         Links = model.Links.Select(link => new Wish.Link
         {
             Text = link.Text,
             Url = link.Url
         }).ToArray(),
         Price = model.Price
     });
 }
Exemple #15
0
        public async Task <IActionResult> New(WishViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            RemoveEmptyLinks(model);

            await this.imageService.SaveImageAsync(model.ThumbnailImageFilename, model.ThumbnailImage.OpenReadStream());

            await this.imageService.SaveImageAsync(model.ImageFilename, model.Image.OpenReadStream());

            await this.wishService.CreateWishAsync(this.ToWish(model));

            return(this.RedirectToAction("Index"));
        }
Exemple #16
0
 public IActionResult NewWish(WishViewModel model)
 {
     if (isLogged())
     {
         if (ModelState.IsValid)
         {
             WishItem NewWishItem = new WishItem();
             NewWishItem.Name   = model.Name;
             NewWishItem.UserId = GetUserId();
             _context.WishItems.Add(NewWishItem);
             _context.SaveChanges();
             return(RedirectToAction("MyWishlist"));
         }
         return(View("MyWishlist"));
     }
     return(RedirectToAction("Index", "Home"));
 }
        public ActionResult Index()
        {
            var user  = new WebUser();
            var model = new WishViewModel
            {
                Recommends = _productService.GetRecomendProducts(4)
            };

            if (user.IsAuthorized)
            {
                model.Wishes = _wishService.GetWishs(user.UserId);
            }
            else
            {
                model.Wishes = _wishService.GetCookieWishs();
            }
            return(View(model));
        }
 public IHttpActionResult PostTrip(WishViewModel wish, double reiting, DateTime dateTrip)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         //string currentUser = RequestContext.Principal.Identity.Name;
         Mapper.Initialize(cfg => cfg.CreateMap <WishViewModel, WishDTO>());
         var wishDTO = Mapper.Map <WishViewModel, WishDTO>(wish);
         travelService.AddTripReport(wishDTO, reiting, dateTrip);
         return(Ok());
     }
     catch (ValidationException ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex.Message));
     }
 }
Exemple #19
0
        public IActionResult Index(string wishQuery, string filter, int?page)
        {
            if (string.IsNullOrWhiteSpace(wishQuery) && SessionValueExists("query"))
            {
                wishQuery = GetFromSession <string>("query");
                RemoveFromSession("query");
            }
            ViewBag.Filter = (string.IsNullOrWhiteSpace(wishQuery) ? filter : wishQuery)?.Trim();

            var wishes = _service.GetAll(_user.Id, ViewBag.Filter) as List <Wish>;

            var viewModel = new WishViewModel
            {
                ViewTitle   = "Wish List",
                AlbumWishes = wishes?.Where(x => x.ItemType == ItemType.Album).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                BookWishes  = wishes?.Where(x => x.ItemType == ItemType.Book).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                MovieWishes = wishes?.Where(x => x.ItemType == ItemType.Movie).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                GameWishes  = wishes?.Where(x => x.ItemType == ItemType.Game).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                PopWishes   = wishes?.Where(x => x.ItemType == ItemType.Pop).ToList()?.GroupBy(y => y.Category)?.ToDictionary(d => string.IsNullOrWhiteSpace(d.Key) ? string.Empty : d.Key, d => d.ToList()),
                PageSize    = NUM_WISHES_TO_GET
            };

            return(View(viewModel));
        }
Exemple #20
0
 private static void RemoveEmptyLinks(WishViewModel model)
 {
     model.Links = model.Links
                   .Where(link => !string.IsNullOrEmpty(link.Url))
                   .ToArray();
 }