public async Task <IActionResult> Create(CreateBindingModel advertisement) { if (!ModelState.IsValid) { return(Redirect("/Advertisement/Create")); } var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var advertisementServiceModel = new AdvertisementCreateServiceModel { Name = advertisement.Name, Price = advertisement.Price, Description = advertisement.Description, Condition = advertisement.Condition, CategoryId = advertisement.CategoryId, SubCategoryId = advertisement.SubCategoryId, TownId = advertisement.TownId, Address = advertisement.Address, Number = advertisement.Number, UserId = userId, Images = advertisement.Images, }; await advertisementService.CreateAsync(advertisementServiceModel); await NotifyOnAdCreateAsync(advertisementServiceModel); return(Redirect("/Home/Index")); }
public async Task GetUserWishlistAsync_WithValidUserId_ShouldReturnCorrectly() { var advertisement = new AdvertisementCreateServiceModel() { Name = "OnePlus 7 Pro", Description = "cool phone for everyday use, excellent performance", Price = 800, Condition = ProductCondition.New, CategoryId = "Electronics", SubCategoryId = "Phone", TownId = "testTownId", Address = "str nqkoq", Number = "telefonce", UserId = "test1" }; await adService.CreateAsync(advertisement); var ad = await context.Advertisements.FirstOrDefaultAsync(a => a.Name == "OnePlus 7 Pro"); var advertisementWishlist = new UserAdvertisementWishlist { UserId = "test", AdvertisementId = ad.Id, Advertisement = ad, }; await context.UsersAdvertisementsWishlist.AddAsync(advertisementWishlist); await context.SaveChangesAsync(); var ads = await service.GetUserWishlistAsync("test", 1, 1); var actualResult = ads.Count(); var expectedResult = 1; Assert.AreEqual(expectedResult, actualResult); }
public async Task <IActionResult> CreateAsync([FromBody] AdvertisementEntry advertisementEntry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await _channelService.ChannelsExistAsync(advertisementEntry.ChannelIds)) { return(BadRequest()); } var advertisement = await _advertisementService.CreateAsync(advertisementEntry); return(CreatedAtAction(nameof(GetByIdAsync), new { id = advertisement.Id }, null)); }