public IActionResult DeleteDoctor([FromRoute]int id) { var d = new Doctor { IdDoctor = id }; _myDBContext.Attach(d); _myDBContext.Remove(d); _myDBContext.SaveChanges(); return Ok(); }
public IActionResult DeleteComment(int CommentID, int ProductID) { var comment = _context.Comment.SingleOrDefault(p => p.CommentId == CommentID); if (comment != null) { _context.Remove(comment); _context.SaveChanges(); return(GetComments(ProductID)); } return(Content("error")); }
public async Task <IActionResult> Edit(AuthorsViewModel author) { /*if (id != author.AuthorID) * { * return NotFound(); * }*/ if (ModelState.IsValid) { try { var MyAuthor = _context.Author.Find(author.AuthorID); MyAuthor.Name = author.Name; MyAuthor.SurName = author.SurName; foreach (var item in _context.AuthorToBook) { if (item.AuthorID == author.AuthorID) { _context.Remove(item); } } foreach (var item in author.Books) { if (item.Checked) { _context.AuthorToBook.Add(new AuthorToBook() { AuthorID = author.AuthorID, BookID = item.ID }); } } //_context.Update(author); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(author.AuthorID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(author)); }
public IActionResult Delete(int id) { Batch batch = db.Batches.Find(id); if (batch == null) { return(StatusCode(StatusCodes.Status404NotFound, new NullReferenceException("Batch not found."))); } db.RemoveRange(db.Movements.Where(m => m.BatchId == id)); db.Remove(batch); db.SaveChanges(); return(StatusCode(StatusCodes.Status200OK)); }
public async Task <IActionResult> DeleteDbAccount(int id) { var dbaccount = await context.myDbAccts.FindAsync(id); if (dbaccount == null) { return(NotFound()); } context.Remove(dbaccount); await context.SaveChangesAsync(); return(Ok(id)); }
public async Task <bool> DeleteCategory(int id) { try { var productToDelete = await _context.Categories.FindAsync(id); _context.Remove(productToDelete); await _context.SaveChangesAsync(); return(true); } catch (System.Exception e) { return(false); } }
public async Task <ActionResult> Delete(int id) { var exists = await myDBContext.Customers.AnyAsync(x => x.CustomerId == id); if (!exists) { return(NotFound()); } myDBContext.Remove(new Customer() { CustomerId = id }); await myDBContext.SaveChangesAsync(); return(NoContent()); }
public void Delete(T entity) { context.Remove(entity); Save(); }
public void Remove(Purchase purchase) { _context.Remove(purchase); }
public async Task <IActionResult> Edit(int id, [Bind("OrderId,CustomerId,Name,Address,Phone,Email,PayMethod,ShipMethod,ShipCost,Comment,OrderStatus,ShipDate")] Orders order, [Bind("ArrDeleteItem")] string ArrDeleteItem, [Bind("ArrEditItemId")] string ArrEditItemId, [Bind("ArrEditItemQuantity")] string ArrEditItemQuantity) { var emp = HttpContext.Session.GetObject <Employee>("Employee"); if (emp == null) { return(RedirectToAction("Index", "Login")); } //mảng id item xóa string[] arrDeleteItem = new string[] { }; if (ArrDeleteItem.Length > 0) { ArrDeleteItem = ArrDeleteItem.Trim(); arrDeleteItem = ArrDeleteItem.Split(','); } //mảng id item sửa string[] arrEditItemId = new string[] { }; if (ArrDeleteItem.Length > 0) { ArrEditItemId = ArrEditItemId.Trim(); arrEditItemId = ArrEditItemId.Split(','); } //mảng id hình ảnh xóa string[] arrEditItemQuantity = new string[] { }; if (ArrEditItemQuantity.Length > 0) { ArrEditItemQuantity = ArrEditItemQuantity.Trim(); arrEditItemQuantity = ArrEditItemQuantity.Split(','); } Orders orderBefore = _context.Orders.AsNoTracking().SingleOrDefault(p => p.OrderId == order.OrderId); if (orderBefore == null) { return(NotFound()); } order.Total = orderBefore.Total - (int)orderBefore.ShipCost; if (ModelState.IsValid) { try { if (arrDeleteItem.Count() > 0) { foreach (var o in arrDeleteItem) { try { OrderDetail orderDetail = _context.OrderDetail.AsNoTracking().SingleOrDefault(p => p.ProductId == int.Parse(o.Trim()) && p.OrderId == order.OrderId); order.Total -= orderDetail.Price * orderDetail.Quantity; _context.Remove(orderDetail); } catch (Exception) { } } } if (arrEditItemId.Count() > 0) { for (var i = 0; i < arrEditItemId.Count(); ++i) { try { OrderDetail orderDetail = _context.OrderDetail.SingleOrDefault(p => p.ProductId == int.Parse(arrEditItemId[i].Trim()) && p.OrderId == order.OrderId); order.Total = order.Total - (orderDetail.Price * orderDetail.Quantity); orderDetail.Quantity = int.Parse(arrEditItemQuantity[i].Trim()); _context.Update(orderDetail); order.Total = order.Total + (orderDetail.Price * orderDetail.Quantity); } catch (Exception) { } } } if (order.Total == 0) { order.ShipCost = 0; } else if (order.Total < 100000) { order.ShipCost = 20000; } else if (order.Total < 500000) { order.ShipCost = 12000; } else { order.ShipCost = 0; } order.EmployeeId = emp.EmployeeId; order.Total = order.Total + (int)order.ShipCost; order.CreatedDate = orderBefore.CreatedDate; _context.Update(order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrdersExists(order.OrderId)) { return(NotFound()); } else { throw; } } } var orderDetails = await _context.OrderDetail.Where(od => od.OrderId == order.OrderId).Include(p => p.Product).ToListAsync(); ViewBag.orderDetails = orderDetails; ViewData["EmployeeName"] = emp.FirstName + " " + emp.LastName; return(View(order)); }