Exemplo n.º 1
0
        public async Task <IActionResult> Create(CreateOrEditUserViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = viewModel.User;

                var dbUser = new User
                {
                    FirstName  = user.FirstName,
                    LastName   = user.LastName,
                    Email      = user.Email,
                    Phone      = user.Phone,
                    Password   = user.Password,
                    AutoBidAmt = user.AutoBidAmt
                };

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

                TempData["SuccessMessage"] = $"Successfully created user #{user.UserId.ToString()}.";

                return(RedirectToAction("Index"));
            }

            return(await CreateOrEdit(viewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(Item item)
        {
            db.Items.Add(item);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Up()
        {
            if (db.Lots.Count() == 0 || db.Lots.FirstOrDefault().Status == false)
            {
                return(RedirectToAction("Index"));
            }
            if (db.Lots.FirstOrDefault().endDate < DateTimeOffset.UtcNow)
            {
                return(RedirectToAction("EndAuction"));
            }

            Bet newBet = new Bet();

            newBet.User = User.Identity.Name;

            if (db.Bets.Count() != 0)
            {
                newBet.betSize = db.Bets.Max(p => p.betSize) + db.Lots.FirstOrDefault().RateBet;
            }
            else
            {
                newBet.betSize = db.Lots.FirstOrDefault().StartBet;
            }

            db.Lots.FirstOrDefault().ActualCost = newBet.betSize;
            db.Lots.FirstOrDefault().Owner      = User.Identity.Name;
            db.Bets.Add(newBet);

            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("RoleID,ShortDescription,UserRole")] Role role)
        {
            if (ModelState.IsValid)
            {
                _context.Add(role);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(role));
        }
        public async Task <IActionResult> Create([Bind("CategoryId,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("sponsorID,sponsorName,sponsorEmail")] Sponsor sponsor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sponsor);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(sponsor));
        }
        public async Task <IActionResult> Create([Bind("MediaTypeID,MediaDescription")] MediaType mediaType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mediaType);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(mediaType));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("AuctionID,AuctionName,StartDate,EndDate")] Auction auction) //re-add eventId
        {
            if (ModelState.IsValid)
            {
                _context.Add(auction);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(auction));
        }
        public async Task <IActionResult> Create([Bind("ID,FwdDate,BankName,AuctionBidID,FwdRate,AmountBid,CouponAmount,WinAmount")] WinResults winResults)
        {
            if (ModelState.IsValid)
            {
                _context.Add(winResults);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuctionBidID"] = new SelectList(_context.AuctionBids, "ID", "ID", winResults.AuctionBidID);
            return(View(winResults));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("ItemId,sponsorID,CategoryId,ItemName,ItemDescription,ItemValue,OpeningBid,BidIncrement,AuctionId")] Item item)
        {
            if (ModelState.IsValid)
            {
                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            // ViewData["AuctionId"] = new SelectList(_context.Auctions, "AuctionID", "AuctionID", item.AuctionId);
            return(View(item));
        }
        public async Task <ActionResult> Create([Bind(Include = "ItemID,CategoryID,Name,Price,Description,ItemImage")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name", item.CategoryID);
            return(View(item));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("Id,SponsorId,CategoryId,Name,Description,Type,RetailPrice,MinimumBid,OfferExpires,Terms")] Item item)
        {
            if (ModelState.IsValid)
            {
                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Edit", new RouteValueDictionary(new { controller = "Items", action = "Edit", id = item.Id })));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", item.CategoryId);
            ViewData["SponsorId"]  = new SelectList(_context.Sponsors, "Id", "Name", item.SponsorId);
            return(View(item));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id != null)
            {
                User user = await db.Users.FirstOrDefaultAsync(p => p.Id == id);

                if (user != null)
                {
                    db.Users.Remove(user);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            return(NotFound());
        }
Exemplo n.º 14
0
        private async void LndService_OnHoldInvoiceActivated(object sender, Invoice invoice, byte[] preImage)
        {
            Console.WriteLine("In Hodle Activated {0}", invoice);
            try
            {
                var auctionInvoice = JsonSerializer.Deserialize <AuctionInvoice>(invoice.Memo);
                using (var context = new AuctionContext())
                {
                    var auctionEntry = context.AuctionEntries.FirstOrDefault(e => e.PaymentRequest == invoice.PaymentRequest);
                    var auction      = GetAuction(Guid.Parse(auctionInvoice.AuctionId));
                    if (auction.FinishedAt != 0)
                    {
                        await _lndService.CancelHodlInvoice(invoice.RHash.ToByteArray());

                        return;
                    }

                    auctionEntry.ActivatedAt = Utility.Utility.DateTimeToUnix(DateTime.UtcNow);
                    auctionEntry.State       = AuctionEntryState.ACTIVATED;
                    context.AuctionEntries.Update(auctionEntry);

                    Console.WriteLine("activated auction entry {0}", auctionEntry);
                    await context.SaveChangesAsync();
                }
            }catch (Exception e)
            {
                Console.WriteLine("ERROR AT HOLD INVOICE ACTIVATED {0}", invoice);

                await _lndService.CancelHodlInvoice(invoice.RHash.ToByteArray());
            }
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Register(RegisterUser model)
        {
            if (ModelState.IsValid)
            {
                User user = db.Users.FirstOrDefault(u => u.Email == model.Email || u.Nickname == model.Nickname);
                if (user == null)
                {
                    // добавляем пользователя в бд
                    user = new User {
                        Email = model.Email, Password = HashPassword(model.Password), Nickname = model.Nickname, Name = model.Name
                    };
                    Role userRole = await db.Roles.FirstOrDefaultAsync(r => r.Name == "user");

                    if (userRole != null)
                    {
                        user.Role = userRole;
                    }
                    db.Users.Add(user);

                    await db.SaveChangesAsync();

                    await Authenticate(user);                     // аутентификация

                    return(RedirectToAction("Lots", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким email/nickname существует");
                }
            }
            return(View(model));
        }
Exemplo n.º 16
0
        public async Task <AuctioneerModel> RegisterAuctioneer(AuctioneerModel auctioneerModel)
        {
            if (auctioneerModel == null)
            {
                throw new ArgumentNullException(nameof(auctioneerModel));
            }

            using (var db = new AuctionContext())
            {
                var found = db.Auctioneers.Any(a =>
                                               a.UserName.Equals(auctioneerModel.UserName, StringComparison.CurrentCultureIgnoreCase));
                if (found)
                {
                    return(null);
                }

                Auctioneer auctioneer = new Auctioneer
                {
                    FirstName = auctioneerModel.FirstName,
                    LastName  = auctioneerModel.LastName,
                    UserName  = auctioneerModel.UserName,
                    Password  = auctioneerModel.Password,
                    IsAdmin   = auctioneerModel.IsAdmin,
                };

                db.Auctioneers.Add(auctioneer);
                await db.SaveChangesAsync();

                auctioneerModel.Id = auctioneer.Id;
                return(auctioneerModel);
            }
        }
Exemplo n.º 17
0
        public async Task <TraderModel> EditTrader(TraderModel trader)
        {
            if (trader == null)
            {
                throw new ArgumentNullException(nameof(trader));
            }

            using (var db = new AuctionContext())
            {
                var traderEntity = db.Traders.FirstOrDefault(t => t.Id == trader.Id);
                if (traderEntity == null)
                {
                    return(null);
                }

                traderEntity.LegacyForm        = trader.LegacyForm;
                traderEntity.IdentityNumber    = trader.IdentityNumber;
                traderEntity.ApplicantName     = trader.ApplicantName;
                traderEntity.ParticipantName   = trader.ParticipantName;
                traderEntity.ParticipantStatus = trader.ParticipantStatus;
                traderEntity.PhoneNumber       = trader.PhoneNumber;
                traderEntity.Email             = trader.Email;
                traderEntity.BankName          = trader.BankName;
                traderEntity.BankAccountNumber = trader.BankAccountNumber;
                traderEntity.Swift             = trader.Swift;
                traderEntity.AuctionDate       = trader.AuctionDate;

                await db.SaveChangesAsync();

                return(trader);
            }
        }
Exemplo n.º 18
0
        public async Task <TraderModel> AddTrader(TraderModel trader)
        {
            if (trader == null)
            {
                throw new ArgumentNullException(nameof(trader));
            }

            using (var db = new AuctionContext())
            {
                var traderEntity = new Trader()
                {
                    Name              = trader.Name,
                    LegacyForm        = trader.LegacyForm,
                    IdentityNumber    = trader.IdentityNumber,
                    ApplicantName     = trader.ApplicantName,
                    ParticipantName   = trader.ParticipantName,
                    ParticipantStatus = trader.ParticipantStatus,
                    PhoneNumber       = trader.PhoneNumber,
                    Email             = trader.Email,
                    BankName          = trader.BankName,
                    BankAccountNumber = trader.BankAccountNumber,
                    Swift             = trader.Swift,
                    AuctionDate       = trader.AuctionDate
                };

                db.Traders.Add(traderEntity);
                await db.SaveChangesAsync();

                trader.Id = traderEntity.Id;
                return(trader);
            }
        }
Exemplo n.º 19
0
        public async Task <TradingHistoryModel> EditTradingHistory(TradingHistoryModel history)
        {
            if (history == null)
            {
                throw new ArgumentNullException(nameof(history));
            }

            using (var db = new AuctionContext())
            {
                var modifiedRecord = db.TradingHistories.FirstOrDefault(h => h.Id == history.Id);
                if (modifiedRecord == null)
                {
                    return(null);
                }

                var trader     = db.Traders.FirstOrDefault(t => t.Id == (history.Trader == null ? 0 : history.Trader.Id)) ?? modifiedRecord.Trader;
                var lot        = db.Lots.FirstOrDefault(L => L.Id == (history.Lot == null ? 0 : history.Lot.Id)) ?? modifiedRecord.Lot;
                var auctioneer = db.Auctioneers.FirstOrDefault(a => a.Id == (history.Auctioneer == null ? 0 : history.Auctioneer.Id)) ?? modifiedRecord.Auctioneer;


                modifiedRecord.Lot           = lot;
                modifiedRecord.Trader        = trader;
                modifiedRecord.Auctioneer    = auctioneer;
                modifiedRecord.LotId         = lot.Id;
                modifiedRecord.TraderId      = trader.Id;
                modifiedRecord.AuctioneerId  = auctioneer.Id;
                modifiedRecord.BidTime       = history.BidTime;
                modifiedRecord.BidOrder      = history.BidOrder;
                modifiedRecord.RecordedPrice = history.RecordedPrice;

                await db.SaveChangesAsync();

                return(history);
            }
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _context.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    user = new User {
                        Email = model.Email, Password = model.Password
                    };
                    Role userRole = await _context.Roles.FirstOrDefaultAsync(r => r.Name == "user");

                    if (userRole != null)
                    {
                        user.Role = userRole;
                    }

                    _context.Users.Add(user);
                    await _context.SaveChangesAsync();

                    await Authenticate(user); // аутентификация

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
Exemplo n.º 21
0
        public async Task <LotModel> EditLot(LotModel lot)
        {
            if (lot == null)
            {
                throw new ArgumentNullException(nameof(lot));
            }

            using (var db = new AuctionContext())
            {
                var lotEntity = db.Lots.FirstOrDefault(L => L.Id == lot.Id);
                if (lotEntity == null)
                {
                    return(null);
                }

                lotEntity.Name          = lot.Name;
                lotEntity.Description   = lot.Description;
                lotEntity.Quantity      = lot.Quantity;
                lotEntity.Unit          = lot.Unit;
                lotEntity.StartingPrice = lot.StartingPrice;
                lotEntity.CurrentPrice  = lot.CurrentPrice;
                lotEntity.MinimalBid    = lot.MinimalBid;
                lotEntity.BidCount      = lot.BidCount;
                lotEntity.AuctionDate   = lot.AuctionDate;

                await db.SaveChangesAsync();

                return(lot);
            }
        }
Exemplo n.º 22
0
        public async Task <LotModel> AddLot(LotModel lot)
        {
            if (lot == null)
            {
                throw new ArgumentNullException(nameof(lot));
            }

            using (var db = new AuctionContext())
            {
                var lotEntity = new Lot
                {
                    Id            = lot.Id,
                    Name          = lot.Name,
                    Description   = lot.Description,
                    Quantity      = lot.Quantity,
                    Unit          = lot.Unit,
                    StartingPrice = lot.StartingPrice,
                    CurrentPrice  = lot.CurrentPrice,
                    MinimalBid    = lot.MinimalBid,
                    BidCount      = lot.BidCount,
                    AuctionDate   = lot.AuctionDate
                };

                db.Lots.Add(lotEntity);
                await db.SaveChangesAsync();

                lot.Id = lotEntity.Id;
                return(lot);
            }
        }
Exemplo n.º 23
0
        public async Task <RaffleEntry> AddRaffleEntry(string raffleId, long amount, string description)
        {
            var raffle = GetRaffle(raffleId);

            if (raffle == null)
            {
                return(null);
            }
            if (raffle.FinishedAt != -1)
            {
                return(null);
            }
            var raffleEntry = new RaffleEntry
            {
                Amount   = amount,
                Memo     = description,
                Raffle   = raffle,
                RaffleId = raffle.Id,
            };

            raffle.RaffleEntries.Add(raffleEntry);
            using (var context = new AuctionContext())
            {
                context.Raffles.Update(raffle);
                raffleEntry = context.RaffleEntries.Add(raffleEntry).Entity;
                await context.SaveChangesAsync();
            }
            return(raffleEntry);
        }
Exemplo n.º 24
0
 private async Task <Auction> UpdateAuction(Auction auction)
 {
     using (var context = new AuctionContext())
     {
         auction = context.Auctions.Update(auction).Entity;
         await context.SaveChangesAsync();
     }
     return(auction);
 }
Exemplo n.º 25
0
 private async Task <AuctionEntry> UpdateAuctionEntry(AuctionEntry auctionEntry)
 {
     using (var context = new AuctionContext())
     {
         auctionEntry = context.AuctionEntries.Update(auctionEntry).Entity;
         await context.SaveChangesAsync();
     }
     return(auctionEntry);
 }
Exemplo n.º 26
0
 public async Task SaveAsync()
 {
     try
     {
         await database.SaveChangesAsync();
     }
     catch (DbEntityValidationException ex)
     {
         throw new Exception(ex.Message + ex.EntityValidationErrors);
     }
 }
Exemplo n.º 27
0
        public async Task <IActionResult> Post(List <IFormFile> files, int itemId)
        {
            var fName     = "";
            var fPath     = "";
            var ext       = "";
            var shortPath = "";

            if (files.Count == 0)
            {
                return(RedirectToAction("UploadView"));
            }

            //TODO: Create method for handling file paths
            foreach (var formFile in files)
            {
                fName = Path.GetFileName(formFile.FileName);
                ext   = Path.GetExtension(formFile.FileName).ToLower();

                //create our folder directory in the wwwroot folder
                fPath = createFilePath(itemId, fName, ref shortPath);

                if (formFile.Length > 0)
                {
                    using (var stream = new FileStream(fPath, FileMode.Create))
                    {
                        await formFile.CopyToAsync(stream);
                    }
                }
            }

            // create media model to store image data in db
            Media image = new Media()
            {
                MediaPath = shortPath,
                MediaName = fName,
                ItemId    = itemId,
            };


            _context.Media.Add(image);
            await _context.SaveChangesAsync();

            // return Ok(new { count = files.Count, size, filePath, fName, test });

            if (itemId == 0)
            {
                return(RedirectToAction("UploadView"));
            }
            else
            {
                return(RedirectToAction("UploadItemImage", "Items", new { id = itemId }));
            }
        }
Exemplo n.º 28
0
        public async Task <AuctionEntry> RequestAuctionEntryInvoice(Guid auctionId, long amount, string winningMessage)
        {
            var auction = GetAuction(auctionId);

            if (auction == null)
            {
                return(null);
            }
            var guid           = Guid.NewGuid();
            var auctionInvoice = new AuctionInvoice
            {
                Amount         = amount,
                AuctionId      = auction.Id.ToString(),
                WinningMessage = winningMessage,
                AuctionEntryId = guid.ToString(),
            };

            var description = JsonSerializer.Serialize <AuctionInvoice>(auctionInvoice);
            var expiry      = (auction.Duration + auction.StartedAt) - Utility.Utility.DateTimeToUnix(DateTime.UtcNow);

            if (expiry < 1)
            {
                return(null);
            }
            var invoice = await _lndService.GetHoldInvoice(amount, description, expiry);

            var auctionEntry = new AuctionEntry
            {
                Id             = guid,
                State          = AuctionEntryState.CREATED,
                Amount         = amount,
                Description    = description,
                AuctionId      = auction.Id,
                PaymentHash    = invoice.paymentHash,
                Preimage       = invoice.preImage,
                PaymentRequest = invoice.payreq,
                Message        = winningMessage,
                CreatedAt      = Utility.Utility.DateTimeToUnix(DateTime.UtcNow)
            };

            using (var context = new AuctionContext())
            {
                auctionEntry = context.AuctionEntries.Add(auctionEntry).Entity;
                await context.SaveChangesAsync();
            }

            Console.WriteLine("created auction entry {0}", auctionEntry);
            return(auctionEntry);
        }
Exemplo n.º 29
0
        public async Task <Raffle> EndRaffle(string raffleId)
        {
            var raffle = GetRaffle(raffleId);

            if (raffle == null)
            {
                return(null);
            }
            raffle.FinishedAt = DateTime.UtcNow.ToFileTimeUtc();
            using (var context = new AuctionContext())
            {
                context.Raffles.Update(raffle);
                await context.SaveChangesAsync();
            }
            return(raffle);
        }
Exemplo n.º 30
0
        public async Task <Raffle> StartRaffle()
        {
            var raffle = new Raffle()
            {
                FinishedAt    = -1,
                StartedAt     = DateTime.UtcNow.ToFileTimeUtc(),
                RaffleEntries = new List <RaffleEntry>()
            };

            using (var context = new AuctionContext())
            {
                raffle = context.Raffles.Add(raffle).Entity;
                await context.SaveChangesAsync();
            }
            return(raffle);
        }