Example #1
0
        public async Task <IActionResult> PostValue([FromBody] Value value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _dbContext.Values.Add(value);
            try
            {
                await _dbContext.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ValueExists(value.Id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetValue", new { id = value.Id }, value));
        }
Example #2
0
        public async Task <IActionResult> PutAddress([FromRoute] int id, [FromBody] Address address)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != address.AddressId)
            {
                return(BadRequest());
            }

            _context.Entry(address).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public async Task <IActionResult> PutOrderdetail([FromRoute] int id, [FromBody] Orderdetail orderdetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != orderdetail.Id)
            {
                return(BadRequest());
            }

            _context.Entry(orderdetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderdetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutShopcart([FromRoute] int id, [FromBody] Shopcart shopcart)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != shopcart.CartId)
            {
                return(BadRequest());
            }

            _context.Entry(shopcart).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShopcartExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Value value)
        {
            if (ModelState.IsValid)
            {
                _context.Add(value);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(value));
        }
Example #6
0
        public static async Task FinishRaffle(int RaffleId, ulong UserId)
        {
            using (var DbContext = new SQLiteDbContext())
            {
                var raffle = DbContext.Raffles.Find(RaffleId);
                raffle.WinnerId = UserId;
                await SaveTokens(UserId, raffle.TokenPrize);

                await DbContext.SaveChangesAsync();
            }
        }
Example #7
0
        public static async Task JoinRaffle(int RaffleId, ulong UserId)
        {
            RaffleEntries entry = new RaffleEntries {
                RaffleId = RaffleId, UserId = UserId
            };

            using (var DbContext = new SQLiteDbContext())
            {
                DbContext.RaffleEntries.Add(entry);
                await DbContext.SaveChangesAsync();
            }
        }
Example #8
0
        public async Task UpdateAsync(Team team)
        {
            var entity = await context.Teams.FindAsync(team.Id);

            if (entity != null)
            {
                entity.Country    = team.Country;
                entity.Name       = team.Name;
                entity.Eliminated = team.Eliminated;

                await context.SaveChangesAsync();
            }
        }
Example #9
0
        public static async Task <int> AddRaffle(string Name, DateTime End, int Prize)
        {
            Raffle raffle = new Raffle {
                CreateDate = DateTime.Now, DoneDate = End, RaffleName = Name, TokenPrize = Prize
            };

            using (var DbContext = new SQLiteDbContext())
            {
                DbContext.Raffles.Add(raffle);
                await DbContext.SaveChangesAsync();

                return(raffle.Id);
            }
        }
Example #10
0
 public static async Task SaveTokens(ulong UserId, int Amount)
 {
     using (var DbContext = new SQLiteDbContext())
     {
         var token = DbContext.PlayTokens.Find(UserId);
         if (token == null)
         {
             DbContext.PlayTokens.Add(new PlayToken
             {
                 UserId = UserId,
                 Amount = Amount
             });
         }
         else
         {
             token.Amount += Amount;
             DbContext.PlayTokens.Update(token);
         }
         await DbContext.SaveChangesAsync();
     }
 }
Example #11
0
        public async Task AddAsync(PaymentRequest paymentRequest)
        {
            await _context.AddAsync(paymentRequest);

            await _context.SaveChangesAsync();
        }