public async Task InsertSaleAsync(SaleAdmin saleAdmin) { saleAdmin.DateInsert = DateTime.Now; var saleId = await _insertAdminRepository.InsertAsync(saleAdmin); await InsertKeyword(saleAdmin.Keywords, saleAdmin.KeywordIds, saleId); }
public IActionResult InsertItem(SaleAdminViewModel saleAdminViewModel, bool?bDisabled) { if (ModelState.IsValid) { SaleAdmin saleAdmin = Mapper.Map <SaleAdmin>(saleAdminViewModel); _adminService.InsertSale(saleAdmin); } return(View("Index")); }
public async Task InsertItemAsync([FromBody] SaleAdminViewModel saleAdminViewModel) { if (ModelState.IsValid) { SaleAdmin saleAdmin = Mapper.Map <SaleAdmin>(saleAdminViewModel); var searchShopName = Regex.Replace(saleAdmin.NameShop, @"\s+", "").ToLower(); saleAdmin.FkShop = (await _adminService.GetShopByName(searchShopName))?.Id ?? (await _adminService.InsertShop(saleAdmin.NameShop, searchShopName)); await _adminService.InsertSaleAsync(saleAdmin); } }
public void TestMethod6() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "Vuelto6") .Options; using (var context = new AppDbContext(options)) { SaleAdmin adm = new SaleAdmin(context); var result = adm.SaveSale(0, 0); Assert.AreEqual("El total no puede ser 0.", result); } }
public void TestMethod5() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "Vuelto5") .Options; using (var context = new AppDbContext(options)) { SaleAdmin adm = new SaleAdmin(context); var result = adm.SaveSale(-125, 100); Assert.AreEqual("No se aceptan valores negativos.", result); } }
public void TestMethod4() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "Vuelto4") .Options; using (var context = new AppDbContext(options)) { SaleAdmin adm = new SaleAdmin(context); var result = adm.SaveSale(125, 100); Assert.AreEqual("Total no puede ser mayor que monto pagado.", result); } }
public void TestMethod2() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "Vuelto2") .Options; using (var context = new AppDbContext(options)) { context.Banknotes.Add(new Banknotes { Id = 1, Value = 100 }); context.Banknotes.Add(new Banknotes { Id = 2, Value = 50 }); context.Banknotes.Add(new Banknotes { Id = 3, Value = 20 }); context.Banknotes.Add(new Banknotes { Id = 4, Value = 10 }); context.SaveChanges(); } using (var context = new AppDbContext(options)) { context.Coins.Add(new Coin { Id = 1, Value = 0.50m }); context.Coins.Add(new Coin { Id = 2, Value = 0.10m }); context.Coins.Add(new Coin { Id = 3, Value = 0.05m }); context.Coins.Add(new Coin { Id = 4, Value = 0.01m }); context.SaveChanges(); } using (var context = new AppDbContext(options)) { SaleAdmin adm = new SaleAdmin(context); var result = adm.SaveSale(20, 100); Assert.AreEqual("Valor do Troco: R$ 80.00.\nEntregar:\n1 nota de R$50.00.\n1 nota de R$20.00.\n1 nota de R$10.00.\n", result); } }
public async Task <int> InsertAsync(SaleAdmin saleAdmin) { string sql = @"INSERT INTO Sale(Name, PriceAfterSale, AveragePrice, OriginPrice, Image, DateInsert, ValidFrom, ValidTo, LinkFirm, Description, bDisabled, PercentSale, FkShop) VALUES(@Name, @PriceAfterSale, @AveragePrice, @OriginPrice, @Image, @DateInsert, @ValidFrom, @ValidTo, @LinkFirm, @Description, @bDisabled, @PercentSale, @FkShop); SELECT CAST(SCOPE_IDENTITY() as int);"; string sql2 = @"INSERT INTO CategorySale(FkCategoryId,FkSaleId) VALUES (@FkCategoryId, @FkSaleId);"; int saleId; using (var connection = new SqlConnection(_options.connectionString)) { saleId = await connection.QuerySingleOrDefaultAsync <int>(sql, new { Name = saleAdmin.Name, PriceAfterSale = saleAdmin.PriceAfterSale, AveragePrice = saleAdmin.AveragePrice, OriginPrice = saleAdmin.OriginPrice, Image = saleAdmin.Image, DateInsert = saleAdmin.DateInsert, ValidFrom = saleAdmin.ValidFrom, ValidTo = saleAdmin.ValidTo, LinkFirm = saleAdmin.LinkFirm, Description = saleAdmin.Description, bDisabled = saleAdmin.Disabled, PercentSale = saleAdmin.PercentSale, FkShop = saleAdmin.FkShop }); try { foreach (var item in saleAdmin.CheckedCategories) { var test = await connection.ExecuteAsync(sql2, new { FkCategoryId = item, FkSaleId = saleId }); } } catch (Exception e) { var test = e; } } return(saleId); }
public void Insert(SaleAdmin saleAdmin) { string sql = @"INSERT INTO Sale(Name, PriceAfterSale, AveragePrice, OriginPrice, Image, DateInsert, ValidFrom, ValidTo, LinkFirm, Description, bDisabled, PercentSale) VALUES(@Name, @PriceAfterSale, @AveragePrice, @OriginPrice, @Image, @DateInsert, @ValidFrom, @ValidTo, @LinkFirm, @Description, @bDisabled, @PercentSale);"; using (var connection = new SqlConnection(_options.connectionString)) { var affRows = connection.Execute(sql, new { Name = saleAdmin.Name, PriceAfterSale = saleAdmin.PriceAfterSale, AveragePrice = saleAdmin.AveragePrice, OriginPrice = saleAdmin.OriginPrice, Image = saleAdmin.Image, DateInsert = saleAdmin.DateInsert, ValidFrom = saleAdmin.ValidFrom, ValidTo = saleAdmin.ValidTo, LinkFirm = saleAdmin.LinkFirm, Description = saleAdmin.Description, bDisabled = saleAdmin.Disabled, PercentSale = saleAdmin.PercentSale }); } }
public SaleController(AppDbContext context) { _admin = new Admin.SaleAdmin(context); }
public void InsertSale(SaleAdmin saleAdmin) { saleAdmin.DateInsert = DateTime.Now; _insertAdminRepository.Insert(saleAdmin); }