public async Task <IActionResult> PutClientPosSetting([FromRoute] int id, [FromBody] ClientPosSettings clientPosSettings) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != clientPosSettings.Id) { return(BadRequest()); } _context.Entry(clientPosSettings).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientPosSettingsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutWishList(int id, WishList wishList) { if (id != wishList.WishListId) { return(BadRequest()); } _context.Entry(wishList).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WishListExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Name,Url,Click,EndTime,ID,IsActive,IsDeleted,ModifiedOn,PhotoURL")] Advertisement advertisement) { if (ModelState.IsValid) { var pictures = Request.Form.Files; for (int i = 0; i < pictures.Count; i++) { var picture = pictures[i]; var fileName = Guid.NewGuid() + Path.GetExtension(picture.FileName); string uploadsFolder = Path.Combine(Environment.WebRootPath, "uploads"); string filePath = Path.Combine(uploadsFolder, fileName); advertisement.PhotoURL = fileName; advertisement.Click = 0; using (var fileStream = new FileStream(filePath, FileMode.Create)) { picture.CopyTo(fileStream); } _context.AddRange(advertisement); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(View(advertisement)); }
public async Task <ActionResult <PurchaseViewModel> > PostPurchase(PurchaseViewModel purchaseVm) { using (var trn = db.Database.BeginTransaction()) { try { Purchase purchase = purchaseVm.purchase; db.Purchase.Add(purchase); await db.SaveChangesAsync(); foreach (PurchaseDetails item in purchaseVm.purchasedetails) { item.PurchaseId = purchase.PurchaseId; db.PurchaseDetails.Add(item); await db.SaveChangesAsync(); } trn.Commit(); } catch (Exception) { trn.Rollback(); } } //return CreatedAtAction("GetPurchase", new { id = Purchase.PurchaseId }, Purchase); return(purchaseVm); }
public async Task <IActionResult> PutCustomers(int id, Customers customers) { if (id != customers.CustomerId) { return(BadRequest()); } _context.Entry(customers).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProductGroup(int id, ProductGroup productGroup) { if (id != productGroup.GroupId) { return(BadRequest()); } _context.Entry(productGroup).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductGroupExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutLog(int id, Log log) { if (id != log.LogId) { return(BadRequest()); } _context.Entry(log).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LogExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProductType([FromRoute] int id, [FromBody] ProductType productType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productType.ProductTypeId) { return(BadRequest()); } productType.ModifiedDate = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Pacific Standard Time"); _context.Entry(productType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUsuario(int id, Usuario usuario) { if (id != usuario.ID) { return(BadRequest()); } _context.Entry(usuario).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsuarioExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBrand(int id, Brand brand) { if (id != brand.BrandId) { return(BadRequest()); } _context.Entry(brand).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BrandExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSizes(int id, Sizes sizes) { if (id != sizes.SizeId) { return(BadRequest()); } _context.Entry(sizes).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SizesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCategory(int id, [FromForm] Category category) { if (id != category.CatId) { return(BadRequest()); } category = await UploadImage(category); _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCompra(int id, Compra compra) { if (id != compra.ID) { return(BadRequest()); } _context.Entry(compra).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompraExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProductInventoryHistory([FromRoute] int id, [FromBody] ProductInventoryHistory productInventoryHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productInventoryHistory.ProductInventoryHistoryId) { return(BadRequest()); } _context.Entry(productInventoryHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductInventoryHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutLocation([FromRoute] int id, [FromBody] Location location) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != location.LocationId) { return(BadRequest()); } _context.Entry(location).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProducts(int id, [FromForm] Products products) { if (id != products.ProductId) { return(BadRequest()); } products = await UploadImage(products); _context.Entry(products).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <int> CreateProdutoReturningIdAsync(ProdutoModel produtoModel) { var produtoAdicionado = await _context.ProdutosModel.AddAsync(produtoModel); await _context.SaveChangesAsync(); return(produtoAdicionado.Entity.Id); }
public async Task <IActionResult> Create([FromBody] CreateOrderViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _db.Users.SingleAsync(x => x.UserName == HttpContext.User.Identity.Name); var order = new Order { DeliveryAddress = new Address { FirstName = model.FirstName, LastName = model.LastName, Address1 = model.Address1, Address2 = model.Address2, TownCity = model.TownCity, County = model.County, Postcode = model.Postcode }, Items = model.Items.Select(x => new OrderItem { ProductId = x.ProductId, ColourId = x.ColourId, StorageId = x.StorageId, Quantity = x.Quantity }).ToList() }; user.Orders.Add(order); await _db.SaveChangesAsync(); var total = await _db.Orders .Where(x => x.Id == order.Id) .Select(x => Convert.ToInt32(x.Items.Sum(i => i.ProductVariant.Price * i.Quantity) * 100)) .SingleAsync(); var charges = new StripeChargeService(); var charge = await charges.CreateAsync(new StripeChargeCreateOptions { Amount = total, Description = $"Order {order.Id} payment", Currency = "GBP", SourceTokenOrExistingSourceId = model.StripeToken }); if (string.IsNullOrEmpty(charge.FailureCode)) { order.PaymentStatus = PaymentStatus.Paid; } else { order.PaymentStatus = PaymentStatus.Declined; } await _db.SaveChangesAsync(); return(Ok(new CreateOrderResponseViewModel(order.Id, order.PaymentStatus))); }
public async Task <IActionResult> Create([Bind("RoleId,Role1")] Role role) { if (ModelState.IsValid) { _context.Add(role); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(role)); }
public async Task <IActionResult> Create([Bind("Id,Titulo,Autor,Editora,Preco")] Livros livros) { if (ModelState.IsValid) { _context.Add(livros); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(livros)); }
public async Task <IActionResult> Create([Bind("PostName,PostUrl,PhotoUrl,Hit,UserID,UserName,PostDate,MyProperty,Description,ID,IsActive,IsDeleted,ModifiedOn")] Blog blog) { if (ModelState.IsValid) { _context.Add(blog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(blog)); }
public async Task <IActionResult> Create([Bind("CategoryID,ProductName,Description,Seller,Number,Publishing,Author,PhotoURL,Pages,Price,Discount,Cost,isFeatured,ThumbnailPictureID,SKU,Tags,Barcode,Supplier,Hit,ID,IsActive,IsDeleted,ModifiedOn")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "ID", product.CategoryID); return(View(product)); }
public async Task <IActionResult> Create([Bind("CategoryName")] Category category) { if (ModelState.IsValid) { category.CategoryId = Guid.NewGuid().ToString(); _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Name,Address,CardNumber,RoleId")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(_context.Role, "RoleId", "Role1", user.RoleId); return(View(user)); }
public async Task <IActionResult> Create([Bind("ParentCategoryID,Name,Description,PictureID,isFeatured,ID,IsActive,IsDeleted,ModifiedOn")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ParentCategoryID"] = new SelectList(_context.Categories, "ID", "ID", category.ParentCategoryID); ViewData["PictureID"] = new SelectList(_context.Pictures, "ID", "ID", category.PictureID); return(View(category)); }
public async Task <IActionResult> Create([Bind("OrderIdFk,ProductIdFk,IdProductOrder")] ProductOrder productOrder) { if (ModelState.IsValid) { _context.Add(productOrder); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["OrderIdFk"] = new SelectList(_context.Order, "OrderId", "OrderId", productOrder.OrderIdFk); ViewData["ProductIdFk"] = new SelectList(_context.Product, "ProductId", "ProductId", productOrder.ProductIdFk); return(View(productOrder)); }
public async Task <IActionResult> Create([Bind("ProductId,RemainingStock")] StockEntry stockEntry) { if (ModelState.IsValid) { stockEntry.StockId = Guid.NewGuid().ToString(); _context.Add(stockEntry); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", stockEntry.ProductId); return(View(stockEntry)); }
public async Task <IActionResult> Create([Bind("ProductId,CategoryId")] ProductCategory productCategory) { if (ModelState.IsValid) { productCategory.IdProductCategory = Guid.NewGuid().ToString(); _context.Add(productCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", productCategory.CategoryId); ViewData["ProductId"] = new SelectList(_context.Product, "ProductId", "ProductName", productCategory.ProductId); return(View(productCategory)); }
public async Task <IActionResult> Detail(int?id) { BlogViewModel vm = new BlogViewModel() { Blog = _blogService.GetBlogByID(id.Value), Products = _productService.GetProductsByView(), Categories = _categoryService.GetCategories() }; if (id == null) { return(View("Error")); } string key = Convert.ToString(id); string value = "K101"; var cookieValue = Request.Cookies[key]; if (cookieValue == null) { CookieOptions cookieOptions = new CookieOptions(); cookieOptions.Expires = DateTime.Now.AddDays(1); Response.Cookies.Append(key, value, cookieOptions); vm.Blog.Hit += 1; } _context.Update(vm.Blog); await _context.SaveChangesAsync(); return(View(vm)); }
public async Task <IActionResult> UploadPicture() { JsonResult result; List <object> pictureJson = new List <object>(); var pictures = Request.Form.Files; for (int i = 0; i < pictures.Count; i++) { var picture = pictures[i]; var fileName = Guid.NewGuid() + Path.GetExtension(picture.FileName); var wwwRootFolder = Path.Combine(_environment.WebRootPath, "uploads"); string filePath = Path.Combine(wwwRootFolder, fileName); using var fileStream = new FileStream(filePath, FileMode.Create); await picture.CopyToAsync(fileStream); Picture newPicture = new Picture() { URL = fileName }; _context.Add(newPicture); await _context.SaveChangesAsync(); pictureJson.Add(new { id = newPicture.ID, pictureURL = newPicture.URL }); } result = new JsonResult(new { Data = pictureJson }); return(result); }