Esempio n. 1
0
        public async Task <Response> Insert(SaleDTO sale)
        {
            using (MarketContext context = new MarketContext())
            {
                Response response = new Response();

                if (sale.TotalPrice <= 0)
                {
                    response.Errors.Add("O valor da venda não pode ser menor ou igual a 0");
                }

                if (sale.ItemsSales.Count <= 0)
                {
                    response.Errors.Add("Não há nenhum produto na venda");
                }

                if (response.Errors.Count != 0)
                {
                    response.Success = false;
                    return(response);
                }

                try
                {
                    context.Sales.Add(sale);
                    await context.SaveChangesAsync();

                    response.Success = true;
                    return(response);
                }
                catch (Exception ex)
                {
                    response.Errors.Add("Erro no banco contate o adm");
                    response.Success = false;
                    File.WriteAllText("Log.txt", ex.Message);
                    return(response);
                }
            }
        }
 public async Task Insert(ClientDTO client)
 {
     _context.Clients.Add(client);
     await _context.SaveChangesAsync();
 }
Esempio n. 3
0
        public async Task AddAsync(Product product)
        {
            await _context.Products.AddAsync(product);

            await _context.SaveChangesAsync();
        }
Esempio n. 4
0
        public async Task <bool> Get([FromQuery] string name,
                                     [FromQuery] int?price,
                                     [FromQuery] Rarity?rarity,
                                     [FromQuery] ItemCategory?category,
                                     [FromQuery(Name = "ext")] bool?extraordinary)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(false);
            }
            if (price == null)
            {
                return(false);
            }
            if (rarity == null)
            {
                return(false);
            }
            if (category == null)
            {
                return(false);
            }
            if (extraordinary == null)
            {
                return(false);
            }

            var ipEntry = await _marketContext.IPs.SingleOrDefaultAsync(k => k.IP == HttpContext.Connection.RemoteIpAddress.ToString());

            if (ipEntry == null)
            {
                ipEntry = new IPEntry()
                {
                    IP = HttpContext.Connection.RemoteIpAddress.ToString()
                };
            }
            if (ipEntry.Blocked)
            {
                return(false);
            }

            var item = await _marketContext.Items.SingleOrDefaultAsync(i => i.Name == name && i.Rarity == rarity);

            if (item == null)
            {
                item = new Item()
                {
                    Name = name, Rarity = rarity, ItemCategory = category, IsExtraordinary = extraordinary
                };
            }
            else
            {
                var mostRecentPrice = await _marketContext.MostRecentPrices.SingleAsync(mrp => mrp.ItemID == item.ID);

                if (mostRecentPrice.Marks == price && mostRecentPrice.Time.AddHours(3) > DateTime.UtcNow)
                {
                    //Ignore duplicated prices if they happen over a small time window
                    return(false);
                }
            }

            var newPrice = new HistoricalPrice()
            {
                Item = item, Marks = price.Value, Time = DateTime.UtcNow, IP = ipEntry
            };

            _marketContext.Prices.Add(newPrice);

            await _marketContext.SaveChangesAsync();

            return(true);
        }
 public async Task Insert(EmployeeDTO employee)
 {
     _context.Employees.Add(employee);
     await _context.SaveChangesAsync();
 }
 public async Task Insert(BrandDTO brand)
 {
     _context.Brands.Add(brand);
     await _context.SaveChangesAsync();
 }
Esempio n. 7
0
 public async Task Insert(ProductDTO product)
 {
     _context.Products.Add(product);
     await _context.SaveChangesAsync();
 }
 public async Task Insert(UserDTO user)
 {
     _context.Users.Add(user);
     await _context.SaveChangesAsync();
 }
Esempio n. 9
0
 public async Task Insert(ProviderDTO provider)
 {
     _context.Providers.Add(provider);
     await _context.SaveChangesAsync();
 }
Esempio n. 10
0
 public async Task Insert(CategoryDTO category)
 {
     _context.Categories.Add(category);
     await _context.SaveChangesAsync();
 }
Esempio n. 11
0
 public async Task SaveAsync()
 {
     await db.SaveChangesAsync();
 }
Esempio n. 12
0
        public async Task CreateAsync(User user)
        {
            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();
        }