public ActionResult DeleteConfirmed(int id) { CarEntity carEntity = _carsRepository.GetWhere(x => x.Id == id).FirstOrDefault(); _carsRepository.Delete(carEntity); return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteMessage(int id, int userId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var messageFromRepo = await _repo.GetMessage(id); if (messageFromRepo.SenderId == userId) { messageFromRepo.SenderDeleted = true; } if (messageFromRepo.RecipientId == userId) { messageFromRepo.RecipientDeleted = true; } if (messageFromRepo.SenderDeleted && messageFromRepo.RecipientDeleted) { _repo.Delete(messageFromRepo); } if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("Error deleting the message"); }
public async Task <IActionResult> DeletePhoto(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var user = await _repo.GetUser(userId); if (!user.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } var photoFromRepo = await _repo.GetPhoto(id); if (photoFromRepo.IsMain) { return(BadRequest("This is the main photo. You cannot delete a main photo.")); } if (photoFromRepo.PublicID != null) { var deleteParams = new DeletionParams(photoFromRepo.PublicID); var result = _cloudinary.Destroy(deleteParams); if (result.Result == "ok") { _repo.Delete(photoFromRepo); } } if (photoFromRepo.PublicID == null) { _repo.Delete(photoFromRepo); } if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete photo.. Try again")); }
public async Task Delete(int id) { var deletedCount = await carsRepository.Delete(id); if (deletedCount == 0) { throw new KeyNotFoundException(); } }
public async Task DeleteCar(Guid id) { var car = await _carsRepo.Delete(id); await _carsRepo.UnitOfWork.SaveChangesAsync(); //await _context.SaveChangesAsync(); _logger.LogWarning("Удалился автомобиль {brand}, {model}", car.Brand.Name, car.ModelName); }
public IActionResult ConfirmDelete(int id, int itemId) { if (id == itemId) { if (_carsRepository.Delete(id)) { return(Content("")); } return(NotFound()); } return(BadRequest()); }
internal void RemoveCars(CarsRemoveVM[] viewModel) { foreach (var item in viewModel) { if (item.Remove) { CarRetire car = new CarRetire { CarId = item.CarId, FlaggedForRetiringDate = DateTime.Now, Retired = true, RetiredDate = DateTime.Now }; if (carRepository.Delete(car).Id > 0) { eventsService.CreateRemovedCarEvent(car); } } } }
public ActionResult Delete(int Id) { var car = _carsRepo.GetCarById(Id); var savepath = Server.MapPath("~/Images"); string fileName = "inventory-"; string extension = Path.GetExtension(car.IMGFilePath); var filePath = Path.Combine(savepath, fileName + car.CarId + extension); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } _carsRepo.Delete(Id); TempData["Success"] = "Vehicle Deleted Successfully! Add or search another car to edit!"; return(RedirectToAction("Index", "Admin")); }
public void Delete(int id) { repository.Delete(id); }
public async Task Delete(int?id) { await _repository.Delete(id); await _repository.SaveChangesAsync(); }
public void Delete(Guid id) { carsRepository.Delete(id); }
public void Delete(string id) { _validator.ValidateDeleteFieldsAreFilled(id); _carsRepository.Delete(id); }