public async Task <IActionResult> PutClothesColors(int id, ClothesColors clothesColors) { if (id != clothesColors.Id) { return(BadRequest()); } _context.Entry(clothesColors).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClothesColorsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSubcategory([FromRoute] int id, [FromBody] Subcategory subcategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != subcategory.Id) { return(BadRequest()); } _context.Entry(subcategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubcategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutMaterial(int id, Material material) { if (id != material.Id) { return(BadRequest()); } _context.Entry(material).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MaterialExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutOrder(int id, Order order) { if (id != order.Id) { return(BadRequest()); } _context.Entry(order).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutType(int id, Models.Type @type) { if (id != @type.Id) { return(BadRequest()); } _context.Entry(@type).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateClient(ulong id, ClientDTO clientDTO) { if (id != clientDTO.Id) { return(BadRequest()); } var client = await _context.Client.FindAsync(id); if (client == null) { return(NotFound()); } client.Firstname = clientDTO.Firstname; client.Lastname = clientDTO.Lastname; client.Address = clientDTO.Address; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!ClientExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task ExecutePurchase(List <Product> boxItems, string email) { var user = await context.User.Include(a => a.CustomerInfo).FirstAsync(a => a.Email == email); var products = await context.Product.Where(a => boxItems.Select(b => b.Id).Contains(a.Id)).ToListAsync(); var costPurchase = 0.0f; boxItems.ForEach(a => { var prod = products.Find(b => b.Id == a.Id); if (prod.Amount < a.Amount) { throw new Exception($"Товара \"{prod.Name}\" недостаточно в магазине"); } else { prod.Amount -= a.Amount; costPurchase += a.Amount * prod.Cost; } }); if (costPurchase > user.CustomerInfo.Balance) { throw new Exception("У вас недостаточно средств на счёте"); } else { user.CustomerInfo.Balance -= costPurchase; } await context.SaveChangesAsync(); var purchase = new Purchase { DateAndTime = DateTime.Now, UserId = user.Id }; await context.Purchase.AddAsync(purchase); await context.SaveChangesAsync(); var purchaseItems = new List <PurchaseProduct>(); boxItems.ForEach(a => { purchaseItems.Add(new PurchaseProduct { PurchaseId = purchase.Id, ProductId = a.Id, ProductAmount = a.Amount }); }); await context.PurchaseProduct.AddRangeAsync(purchaseItems); await context.SaveChangesAsync(); }
public async Task InitializeAsync() { var db = _db.Database; //if (await db.EnsureDeletedAsync()) //{ // //База данных существовала и была успешно удалена //} //await db.EnsureCreatedAsync(); await db.MigrateAsync(); // Автоматическое создание и миграция базы до последней версии await IdentityInitializeAsync(); if (await _db.Products.AnyAsync()) { return; } using (var transaction = await db.BeginTransactionAsync()) { await _db.Sections.AddRangeAsync(TestData.Sections); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Sections] ON"); await _db.SaveChangesAsync(); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Sections] OFF"); transaction.Commit(); } using (var transaction = await db.BeginTransactionAsync()) { await _db.Brands.AddRangeAsync(TestData.Brands); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Brands] ON"); await _db.SaveChangesAsync(); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Brands] OFF"); transaction.Commit(); } using (var transaction = await db.BeginTransactionAsync()) { await _db.Products.AddRangeAsync(TestData.Products); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Products] ON"); await _db.SaveChangesAsync(); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Products] OFF"); transaction.Commit(); } }
public async Task <IActionResult> Create([Bind("Subcategory_id,Name")] Subcategory subcategory) { if (ModelState.IsValid) { _context.Add(subcategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(subcategory)); }
public async Task <IActionResult> Create([Bind("Id,Name,NormalizedName,ConcurrencyStamp")] Role role) { if (ModelState.IsValid) { _context.Add(role); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(role)); }
public async Task <IActionResult> Create([Bind("Poll_id,Question,Active")] Poll poll) { if (ModelState.IsValid) { _context.Add(poll); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(poll)); }
public async Task <IActionResult> Create([Bind("HeadingItem_id,Link,Name,HasChildren,Parent,Item_Column")] HeadingMenu headingMenu) { if (ModelState.IsValid) { _context.Add(headingMenu); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(headingMenu)); }
public async Task AddCustomerAsync(User user, CustomerInfo customerInfo) { await context.AddAsync(user); await context.SaveChangesAsync(); customerInfo.Id = user.Id; await context.CustomerInfo.AddAsync(customerInfo); await context.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("FooterItem_id,Link,Name")] FooterMenu footerMenu) { if (ModelState.IsValid) { _context.Add(footerMenu); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(footerMenu)); }
public async Task <IActionResult> Create([Bind("Slider_id,Active,Title,Text")] Slider slider) { if (ModelState.IsValid) { _context.Add(slider); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(slider)); }
public async Task <IActionResult> Create([Bind("Type_id,Name")] Models.Type @type) { if (ModelState.IsValid) { _context.Add(@type); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(@type)); }
public async Task AddProductAsync(Product product, List <ProductProperty> chars) { await context.Product.AddAsync(product); await context.SaveChangesAsync(); chars.ForEach(item => item.ProductId = product.Id); await context.AddRangeAsync(chars); await context.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("Color_id,Name")] Color color) { if (ModelState.IsValid) { _context.Add(color); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(color)); }
public async Task <IActionResult> Create([Bind("Photo_id,Source,Alt,Slider_id")] SliderPhoto sliderPhoto) { if (ModelState.IsValid) { _context.Add(sliderPhoto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Slider_id"] = new SelectList(_context.Sliders, "Slider_id", "Text", sliderPhoto.Slider_id); return(View(sliderPhoto)); }
public async Task <IActionResult> Create([Bind("Price_id,Net_price,Discount,Active,Product_id")] Price price) { if (ModelState.IsValid) { _context.Add(price); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Product_id"] = new SelectList(_context.Products, "Product_id", "Description", price.Product_id); return(View(price)); }
public async Task <IActionResult> Create([Bind("Photo_id,Source,Alt,Product_id")] ProductPhoto productPhoto) { if (ModelState.IsValid) { _context.Add(productPhoto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Product_id"] = new SelectList(_context.Products, "Product_id", "Description", productPhoto.Product_id); return(View(productPhoto)); }
public async Task <IActionResult> Create([Bind("Option_id,Name,Poll_id")] Option option) { if (ModelState.IsValid) { _context.Add(option); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Poll_id"] = new SelectList(_context.Polls, "Poll_id", "Question", option.Poll_id); return(View(option)); }
public async Task <IActionResult> Create([Bind("Vote_id,UserId,Time,Option_id")] Vote vote) { if (ModelState.IsValid) { _context.Add(vote); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Option_id"] = new SelectList(_context.Options, "Option_id", "Name", vote.Option_id); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", vote.UserId); return(View(vote)); }
public async Task <IActionResult> Create([Bind("Rating_id,Product_id,UserId,Value")] Rating rating) { if (ModelState.IsValid) { _context.Add(rating); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Product_id"] = new SelectList(_context.Products, "Product_id", "Description", rating.Product_id); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", rating.UserId); return(View(rating)); }
public async Task <IActionResult> Create([Bind("Ordered_id,ProductVariant_Id,Order_Id,Amount")] Ordered ordered) { if (ModelState.IsValid) { _context.Add(ordered); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Order_Id"] = new SelectList(_context.Orders, "Order_id", "UserId", ordered.Order_Id); ViewData["ProductVariant_Id"] = new SelectList(_context.ProductVariants, "ProductVariant_Id", "ProductVariant_Id", ordered.ProductVariant_Id); return(View(ordered)); }
public async Task <IActionResult> Create([Bind("Order,CategoryId,BrandId,ImageUrl,Price,Manufacturer,Gender,Id,Name")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BrandId"] = new SelectList(_context.Brands, "Id", "Id", product.BrandId); ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId); return(View(product)); }
public async Task InitializeAsync() { await _context.Database.MigrateAsync(); await InitializeIdentity(); if (await _context.Products.AnyAsync()) { return; } using (var transaction = _context.Database.BeginTransaction()) { await _context.Sections.AddRangeAsync(InitializationData.Sections); await _context.Database.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Sections] ON"); await _context.SaveChangesAsync(); await _context.Database.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Sections] OFF"); transaction.Commit(); } using (var transaction = _context.Database.BeginTransaction()) { await _context.Brands.AddRangeAsync(InitializationData.Brands); await _context.Database.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Brands] ON"); await _context.SaveChangesAsync(); await _context.Database.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Brands] OFF"); transaction.Commit(); } using (var transaction = _context.Database.BeginTransaction()) { await _context.Products.AddRangeAsync(InitializationData.Products); await _context.Database.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Products] ON"); await _context.SaveChangesAsync(); await _context.Database.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Products] OFF"); transaction.Commit(); } }
public async Task InitializeAsync() { var db = _db.Database; await db.MigrateAsync(); await IdentityInitializeAsync(); if (await _db.Products.AnyAsync()) { return; } using (var transaction = await db.BeginTransactionAsync()) { await _db.Sections.AddRangeAsync(TestData.Sections); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Sections] ON"); await _db.SaveChangesAsync(); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Sections] OFF"); transaction.Commit(); } using (var transaction = await db.BeginTransactionAsync()) { await _db.Brands.AddRangeAsync(TestData.Brands); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Brands] ON"); await _db.SaveChangesAsync(); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Brands] OFF"); transaction.Commit(); } using (var transaction = await db.BeginTransactionAsync()) { await _db.Products.AddRangeAsync(TestData.Products); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Products] ON"); await _db.SaveChangesAsync(); await db.ExecuteSqlCommandAsync("SET IDENTITY_INSERT [dbo].[Products] OFF"); transaction.Commit(); } }
public async Task <IActionResult> Create([Bind("ProductVariant_Id,Product_id,Size_id,Color_id,Quantity")] ProductVariant productVariant) { if (ModelState.IsValid) { _context.Add(productVariant); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Color_id"] = new SelectList(_context.Colors, "Color_id", "Name", productVariant.Color_id); ViewData["Product_id"] = new SelectList(_context.Products, "Product_id", "Description", productVariant.Product_id); ViewData["Size_id"] = new SelectList(_context.Sizes, "Size_id", "Name", productVariant.Size_id); return(View(productVariant)); }
public async Task <IActionResult> Create([Bind("Product_id,Name,Description,Category_id,Subcategory_id,Type_id")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Category_id"] = new SelectList(_context.Categories, "Category_id", "Name", product.Category_id); ViewData["Subcategory_id"] = new SelectList(_context.Subcategories, "Subcategory_id", "Name", product.Subcategory_id); ViewData["Type_id"] = new SelectList(_context.Types, "Type_id", "Name", product.Type_id); return(View(product)); }