/// <summary> /// All Car data will be removed when the car delete /// </summary> /// <param name="id">Car Id</param> /// <returns></returns> public IResult Delete(int id) { var DeletedCar = GetById(id).Data; cardal.Delete(DeletedCar); var DeletedCarImages = carImagesDal.GetAll(pre => pre.CarId == DeletedCar.Id); foreach (var deletedCarImage in DeletedCarImages) { carImagesDal.Delete(deletedCarImage); if (!deletedCarImage.ImagePath.Equals("thumbnail.png")) { fileProcess.Delete(deletedCarImage.ImagePath); } } return(new SuccessResult(Messages.Delete_Message(Messages.GetNameDict[typeof(Car)]))); }
public IResult Delete(int id) { IResult result = BusinessRules.Run(CheckTheCarImageExists(FileId: id), CheckTheCarExists(id)); if (result != null) { return(null); } CarImage currentCar = GetById(id).Data; carImagesDal.Delete(currentCar); if (!currentCar.ImagePath.Equals("thumbnail.png")) // Delete it if current car's image is not thumbnail. { fileProcess.Delete(currentCar.ImagePath); } return(new SuccessResult(Messages.Add_Message(Messages.GetNameDict[typeof(CarImage)]))); }