public ActionResult Create(CreateAuctionViewModel newAuction)
        {
            if (ModelState.IsValid)
            {
                AuctionDto auction = new AuctionDto();
                auction.Name      = newAuction.Name;
                auction.Price     = newAuction.Price;
                auction.Seller_Id = Convert.ToInt32(Session["UserId"]);
                //auction.Seller.UserName = Session["UserName"].ToString();
                auction.Description = newAuction.Description;
                auction.Image_Path  = newAuction.Image_Path;
                if (auction.Image_Path == null)
                {
                    auction.Image_Path = "http://www.bernunlimited.com/c.4436185/sca-dev-vinson/img/no_image_available.jpeg";
                }

                try
                {
                    _auctionService.CreateAuction(auction);
                }
                catch
                {
                    return(Content("Insert error"));
                }


                return(RedirectToAction("Index", "Home", null));
            }
            else
            {
                return(Content("Error"));
            }
        }
        public async Task <ActionResult <AuctionModel> > Post([FromBody] CreateAuctionResource auctionBody)
        {
            var auction = await _auctionService.CreateAuction(auctionBody);

            var result = _mapper.Map <AuctionModel>(auction);

            return(CreatedAtAction(nameof(Get), new { id = result.Id }, result));
        }
Example #3
0
        public async Task <ActionResult> CreateAuction(AuctionViewModel auctionVm)
        {
            if (ModelState.IsValid)
            {
                if (auctionVm.LotInformation.UploadedImage != null && auctionVm.LotInformation.UploadedImage.ContentLength > 0)
                {
                    if (_allowedMimetypes.Contains(auctionVm.LotInformation.UploadedImage.ContentType))
                    {
                        string userId = AuthenticationManager.User.Claims.ElementAt(0).Value;

                        Auction auction = new Auction
                        {
                            LotPhoto = new LotPhoto
                            {
                                FileName    = Path.GetFileName(auctionVm.LotInformation.UploadedImage.FileName),
                                ContentType = auctionVm.LotInformation.UploadedImage.ContentType
                            },
                            Title        = auctionVm.LotInformation.Title,
                            StartPrice   = auctionVm.LotInformation.StartPrice,
                            TradingStart = auctionVm.TradingStart,
                            UserId       = userId,
                        };
                        using (var reader = new BinaryReader(auctionVm.LotInformation.UploadedImage.InputStream))
                        {
                            auction.LotPhoto.Content = reader.ReadBytes(auctionVm.LotInformation.UploadedImage.ContentLength);
                        }

                        await _auctionService.CreateAuction(auction);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("LotPhoto", "Некорректный формат изображения");
                    }
                }
                else
                {
                    ModelState.AddModelError("LotPhoto", "Изображение не было получено");
                }
            }

            return(View(auctionVm));
        }
        public ActionResult Create(AuctionItemViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ErrorMessage = "All fields are required.";
                return(View(viewModel));
            }

            float minAmount;

            if (!float.TryParse(viewModel.MinAmount, out minAmount))
            {
                ViewBag.ErrorMessage = "Wrong format for minimum amount. Please input the correct number.";
                return(View());
            }

            _auctionService.CreateAuction(UserSession.CurrentUser.Username, viewModel);
            return(RedirectToAction("Index"));
        }
        public void GivenTwoAuctionsWhenGetAllAuctionsThenBothAuctionsReturned()
        {
            // Arrange
            _userService.CreateUser(username, password);
            var auctionItem1 = new AuctionItemBuilder()
                               .WithMinAmount("100")
                               .Build();

            //new AuctionItemViewModel
            //{
            //    Description = "Description",
            //    MinAmount = "100",
            //    Name = "Auction item"
            //};
            var auctionItem2 = new AuctionItemViewModel {
                Description = "Description 2",
                MinAmount   = "100",
                Name        = "Auction item 2"
            };

            _auctionService.CreateAuction(username, auctionItem1);
            _auctionService.CreateAuction(username, auctionItem2);


            // Act
            var auctions = _auctionService.GetAllAuctions();

            // Assert
            Assert.IsNotEmpty(auctions);
            Assert.AreEqual(2, auctions.Count());
        }
Example #6
0
        public async Task <IActionResult> CreateAuction([FromBody] AuctionCreationDto auctionDto)
        {
            var createdAuction = await _auctionService.CreateAuction(auctionDto);

            return(CreatedAtRoute("GetAuction", new { id = createdAuction.AuctionID }, createdAuction));
        }
Example #7
0
 // POST: api/Auction
 public void Post([FromBody] Data.Auction auction)
 {
     _auctionService.CreateAuction(auction);
 }