public async Task <IActionResult> PutBrand([FromBody] Brand brand) { _context.Entry(brand).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> PutCustomerCart([FromRoute] string id, [FromBody] CustomerCart customerCart) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customerCart.CustomerCartId) { return(BadRequest()); } _context.Entry(customerCart).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerCartExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutOrder([FromRoute] int id, [FromBody] Order order) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order.OrderId) { 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> PutGeneralImage([FromRoute] string id, [FromBody] GeneralImage generalImage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != generalImage.GeneralImageId) { return(BadRequest()); } _context.Entry(generalImage).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GeneralImageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutShippingInfo([FromRoute] int id, [FromBody] ShippingInfo shippingInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shippingInfo.ShippingInfoId) { return(BadRequest()); } _context.Entry(shippingInfo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShippingInfoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProductStatus([FromRoute] int id, [FromBody] ProductStatus productStatus) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productStatus.ProductStatusId) { return(BadRequest()); } _context.Entry(productStatus).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductStatusExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCategory([FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> PutProduct([FromBody] Product product) { // if (!ModelState.IsValid) // { // return BadRequest(ModelState); // } var oldProduct = await _context.Product.FindAsync(product.ProductId); if (oldProduct.ProductStatusId != product.ProductStatusId) { if (_context.ProductStatus.Find(oldProduct.ProductStatusId).StatusCode.ToLower() == "soldout") { var newStatus = _context.ProductStatus.Find(product.ProductStatusId).StatusCode.ToLower(); if (newStatus == "available") { if (oldProduct.CurrentQuantity < product.CurrentQuantity) { var productNotifyList = _context.ProductNotification.FromSql( $"SELECT * FROM ProductNotification WHERE ProductID = {oldProduct.ProductId} AND NotifyStatus = 0").AsNoTracking(); if (productNotifyList.Any()) { var listEmail = await productNotifyList.Select(x => new EmailAddress { Email = x.Email }).ToListAsync(); var thumbImageUrl = _context.GeneralImage.Find(oldProduct.ProductThumbImage).ImageUrl; var result = await _emailSender.SendEmailProductAvailableAsync(new GetProductEmailDTO { Name = oldProduct.Name, Slug = oldProduct.Slug, ThumbImageUrl = thumbImageUrl }, listEmail); if (result.StatusCode == HttpStatusCode.Accepted) { // await _context.ProductNotification // .Where(x => x.ProductId == oldProduct.ProductId) // .ForEachAsync(x => x.NotifyStatus = true); _context.ProductNotification.RemoveRange(productNotifyList); await _context.SaveChangesAsync(); } } } } } } if (oldProduct.CategoryId != product.CategoryId) { var oldCategory = _context.Category.Find(oldProduct.CategoryId); oldCategory.TotalProduct--; var newCategory = _context.Category.Find(product.CategoryId); newCategory.TotalProduct++; await _context.SaveChangesAsync(); } if (oldProduct.BrandId != product.BrandId) { var oldBrand = _context.Brand.Find(oldProduct.CategoryId); oldBrand.TotalProduct--; var newBrand = _context.Brand.Find(product.CategoryId); newBrand.TotalProduct++; await _context.SaveChangesAsync(); } if (oldProduct != null) { oldProduct.BrandId = product.BrandId; oldProduct.CategoryId = product.CategoryId; oldProduct.Name = product.Name; oldProduct.ProductStatusId = product.ProductStatusId; oldProduct.ProductLongDesc = product.ProductLongDesc; oldProduct.ProductShortDesc = product.ProductShortDesc; oldProduct.MaximumQuantity = product.MaximumQuantity; oldProduct.DisplayPrice = product.DisplayPrice; oldProduct.CurrentQuantity = product.CurrentQuantity; oldProduct.RealPrice = product.RealPrice; oldProduct.Weight = product.Weight; oldProduct.IsHide = product.IsHide; } _context.Entry(oldProduct).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(NotFound()); } return(Ok()); }