Esempio n. 1
0
        // POST api/<controller>
        public bool Post([FromBody] CreateAuctionViewModel vmodel)
        {
            CreateAuctionModel model = new CreateAuctionModel();

            model.CreateAuction(vmodel);
            return(true);
        }
        public async Task <ActionResult> CreateAuction(CreateAuctionModel model)
        {
            if (ModelState.IsValid)
            {
                var auction = new Auction
                {
                    IdUser      = User.Identity.GetUserId(),
                    Name        = model.AuctionName,
                    Duration    = (model.Duration == 0) ? SystemParameters.DEFAULT_AUCTION_DURATION : model.Duration,
                    Photo       = model.PhotoURL,
                    PriceStart  = model.PriceStart,
                    PriceNow    = model.PriceStart,
                    State       = "READY",
                    TimeCreate  = System.DateTime.Now,
                    TotalTokens = 0
                };

                var db = new auctiondbEntities();
                db.Auctions.Add(auction);
                await db.SaveChangesAsync();

                return(Redirect("/"));
            }
            return(View());
        }
        // GET: UserFunctionalities
        public ActionResult CreateAuction()
        {
            ViewBag.Message = "Create Auction page.";
            var model = new CreateAuctionModel();

            return(View(model));
        }
        public IActionResult CreateAuction()
        {
            CreateAuctionModel model = new CreateAuctionModel()
            {
                openDate = DateTime.UtcNow
            };

            return(View(model));
        }
Esempio n. 5
0
        public async Task <IActionResult> CreateAuction(CreateAuctionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string[] arr1 = model.openTime.Split(':', 3);
            string[] arr2 = model.closeTime.Split(':', 3);

            TimeSpan ts1 = new TimeSpan(Convert.ToInt32(arr1[0]), Convert.ToInt32(arr1[1]), Convert.ToInt32(arr1[2]));
            TimeSpan ts2 = new TimeSpan(Convert.ToInt32(arr2[0]), Convert.ToInt32(arr2[1]), Convert.ToInt32(arr2[2]));

            model.openDate  = model.openDate.Date + ts1;
            model.closeDate = model.closeDate.Date + ts2;

            // if(DateTime.Compare(DateTime.Now, model.openDate)>0)
            // {
            //     ModelState.AddModelError("", "Invalid open date! (minimal time is +5minuts form now)");
            //     return View(model);
            // }
            if (DateTime.Compare(model.openDate, model.closeDate) > 0)
            {
                ModelState.AddModelError("", "Close date must be greater than open date!");
                return(View(model));
            }

            User user = await this.userManager.GetUserAsync(base.User);

            using (BinaryReader reader = new BinaryReader(model.file.OpenReadStream( ))) {
                Auction auction = new Auction( )
                {
                    name         = model.name,
                    description  = model.description,
                    startPrice   = model.startPrice,
                    currentPrice = model.startPrice,
                    createDate   = DateTime.Now,
                    openDate     = model.openDate,
                    closeDate    = model.closeDate,
                    state        = "Draft",
                    winner       = null,
                    owner        = user,
                    image        = reader.ReadBytes(Convert.ToInt32(reader.BaseStream.Length))
                };

                await this.context.Auctions.AddAsync(auction);

                await this.context.SaveChangesAsync( );

                await this.AuctionOpenTask(auction.Id, auction.openDate);
            }



            return(RedirectToAction(nameof(AuctionController.Index), "Auction"));
        }
Esempio n. 6
0
        public IActionResult CreateAuction()
        {
            DateTime date = DateTime.Now;

            string hours   = date.Hour > 9 ? date.Hour.ToString() : date.Hour.ToString().PadLeft(2, '0');
            string minutes = date.Minute > 9 ? date.Minute.ToString() : date.Minute.ToString().PadLeft(2, '0');
            string seconds = date.Second > 9 ? date.Second.ToString() : date.Second.ToString().PadLeft(2, '0');
            string time    = hours + ":" + minutes + ":" + seconds;

            CreateAuctionModel model = new CreateAuctionModel()
            {
                openDate  = date,
                openTime  = time,
                closeDate = date.AddDays(1),
                closeTime = time,
            };

            return(View(model));
        }
 public ActionResult Create(CreateAuctionModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var userId = ((UserPrincipal)(HttpContext.User)).Id;
             _auctionBl.CreateAuction(model, userId);
             return(RedirectToAction("Index"));
         }
         logger.Info("Model state invalid.");
         return(View());
     }
     catch (Exception e)
     {
         logger.Info("Exception occured, redirecting to create auction page. " + e.Message);
         return(View());
     }
 }
Esempio n. 8
0
        public void CreateAuction(CreateAuctionModel model, Guid userId)
        {
            var auction = new Auction
            {
                Id          = Guid.NewGuid(),
                UserId      = userId,
                Name        = model.Name,
                Description = model.Description,
                Price       = model.Price,
                Duration    = model.Duration
            };
            var target = new MemoryStream();

            model.Image.InputStream.CopyTo(target);
            var data = target.ToArray();

            auction.Image    = data;
            auction.StatusId = _auctionStatusRepository.GetByType("READY").Id;
            _auctionRepository.Save(auction);
        }
Esempio n. 9
0
        public async Task <IActionResult> Create(CreateAuctionModel auctionModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(auctionModel));
            }

            // Dohvatam ID ulogovanog Usera
            string loggedUserId = User.FindFirst("id").Value;

            Auction auction = new Auction( )
            {
                name         = auctionModel.name,
                description  = auctionModel.description,
                startPrice   = auctionModel.startPrice,
                currentPrice = auctionModel.startPrice,
                createDate   = DateTime.Now,
                openDate     = auctionModel.openDate,
                closeDate    = auctionModel.closeDate,
                state        = Auction.AuctionState.DRAFT,
                ownerId      = loggedUserId,
                owner        = await _context.Users.FirstOrDefaultAsync(u => u.Id.Equals(loggedUserId))
            };


            using (BinaryReader reader = new BinaryReader(auctionModel.image.OpenReadStream( ))) {
                auction.image = reader.ReadBytes(Convert.ToInt32(reader.BaseStream.Length));
            };

            _context.Add(auction);
            await _context.SaveChangesAsync();

            if (User.FindFirst(ClaimTypes.Role).Value == "Admin")
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(RedirectToAction(nameof(MyAuctions), "Auction"));
            }
        }
        public ActionResult CreateAuction(CreateAuctionModel auction)
        {
            if (this.ModelState.IsValid)
            {
                var item = this.dataItem.All().FirstOrDefault(i => i.Title == auction.ItemTitle);

                var items = new List<Item> { item };
                if (item == null)
                {
                    this.TempData["Success"] = "There is no such Item";

                    return this.View("CreateAuction", auction);
                }

                var bidders = new List<User>();

                this.dataAuction.Add(new Auction
                {
                    Name = auction.Name,
                    Items = items,
                    DateOfAuction = auction.DateOfAuction,
                    Bidders = bidders,
                    InitialPrice = auction.InitialPrice,
                    BidStep = auction.BidStep
                });


                this.dataAuction.Save();

                this.TempData["Success"] = "You have successfully created Auction";

                return this.RedirectToAction("CreateAuction");
            }

            return this.View("CreateAuction", auction);
        }
        public async Task <IActionResult> CreateAuction(CreateAuctionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            User loggedInUser = await this.userManager.GetUserAsync(base.User);

            if (model.openHour > 0)
            {
                model.openDate = model.openDate.AddHours(Convert.ToDouble(model.openHour));
            }

            if (model.openMinute > 0)
            {
                model.openDate = model.openDate.AddMinutes(Convert.ToDouble(model.openMinute));
            }

            if (model.closeHour > 0)
            {
                model.closeDate = model.closeDate.AddHours(model.closeHour);
            }

            if (model.closeMinute > 0)
            {
                model.closeDate = model.closeDate.AddMinutes(model.closeMinute);
            }

            if (model.openDate < DateTime.Now)
            {
                ModelState.AddModelError("", "Open date not valid!");
                return(View(model));
            }

            if (model.openDate >= model.closeDate)
            {
                ModelState.AddModelError("", "Open date and Close date not valid!");
                return(View(model));
            }

            if (!Microsoft.VisualBasic.Information.IsNumeric(model.startPrice))
            {
                ModelState.AddModelError("", "Start price not valid!");
                return(View(model));
            }

            await Console.Out.WriteLineAsync(model.openDate + "===" + model.closeDate);

            await Console.Out.WriteLineAsync(model.openDate + "===" + model.closeDate);

            await Console.Out.WriteLineAsync(model.openDate + "===" + model.closeDate);

            using (BinaryReader reader = new BinaryReader(model.image.OpenReadStream( ))) {
                Auction auction = new Auction( )
                {
                    name         = model.name,
                    description  = model.description,
                    startPrice   = Convert.ToInt32(model.startPrice),
                    currentPrice = Convert.ToInt32(model.startPrice),
                    createDate   = DateTime.Now,
                    openDate     = model.openDate,
                    closeDate    = model.closeDate,
                    state        = "DRAFT",
                    owner        = loggedInUser,
                    winner       = null,
                    image        = reader.ReadBytes(Convert.ToInt32(reader.BaseStream.Length))
                };

                await this.context.Auctions.AddAsync(auction);

                await this.context.SaveChangesAsync( );

                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }
        }
        public ActionResult EditAuction(CreateAuctionModel model)
        {
            if (this.ModelState.IsValid)
            {
                var auction = this.dataAuction.All().FirstOrDefault(a => a.Name == model.Name);

                if(auction == null)
                {
                    TempData["Failure"] = "There is no auction with that name!";

                    return this.View(model);
                }

                var itemsToRemove = auction.Items.ToList();
                foreach(var item in itemsToRemove)
                {
                    auction.Items.Remove(item);
                }

                var itemToAdd = this.dataItem.All().FirstOrDefault(i => i.Title == model.ItemTitle);
                if (itemToAdd == null)
                {
                    this.TempData["Failure"] = "There is no such Item";

                    return this.View(model);
                }

                auction.Name = model.Name;
                auction.Items.Add(itemToAdd);
                auction.DateOfAuction = model.DateOfAuction;
                auction.InitialPrice = model.InitialPrice;
                auction.BidStep = model.BidStep;

                this.dataAuction.Save();

                this.TempData["Success"] = "You have successfully updated the auction!";

                return this.RedirectToAction("ListAllAuctions", "PublicAuction", new { area = string.Empty });
            }

            return this.View(model);
        }