public async Task Delete(int id, string userId, bool isSold) { var horseAd = _iHorseAdDao.GetById(id); CheckHorseAdAndUserIdentity(horseAd, userId); var associatedAppointments = _iAppointmentDao.GetAppointmentsByHorseAdvertismentId(horseAd.Id); if (associatedAppointments != null && associatedAppointments.Any()) { foreach (var appointment in associatedAppointments) { appointment.IsCanceled = true; _iAppointmentDao.UpdateAppointment(appointment); await SendAppointmentCanceledEmailToInitiator(appointment, horseAd); } } horseAd.IsDeleted = true; horseAd.IsSold = isSold; await _iHorseAdDao.UpdateAsync(horseAd); }
public async Task DeleteUserById(string userId) { var userModel = _iUserDao.FindUserById(userId); CheckIfUserExists(userModel); if (userModel.HorseAds?.Count > 0) { foreach (var horseAdsId in userModel.HorseAds.Select(x => x.Id)) { var horseAd = _iHorseAdDao.GetById(horseAdsId); horseAd.IsDeleted = true; await _iHorseAdDao.UpdateAsync(horseAd); } userModel.HorseAds.Clear(); } await _iUserDao.DeleteUser(userModel); }