public int DeleteCenter(Centers center) { int output = 0; Utilities.Try(() => { using (var trans = new TransactionScope()) { var contact = _centerContactRepo.GetCenterContactByCenterId(center.Id); if (contact.Count() > 0) { foreach (var c in contact) { c.IsDeleted = false; c.IsActive = true; var ct = _centerContactRepo.ContactUpdate(c); if (ct > 0) { var user = _userRepo.GetUserById(Convert.ToInt32(c.UserId)); if (user != null) { user.IsActive = true; user.IsDeleted = false; _userRepo.Update(user); } } else { throw new Exception("Unable to delete center with contacts.,"); } } } var centtrans = _centerTransRepo.GetCenterTransByCenterId(center.Id); if (centtrans.Count > 0) { foreach (var t in centtrans) { t.IsActive = true; t.IsDeleted = false; _centerTransRepo.UpdateCenterTrans(t); } } output = _centerRepo.DeleteCenter(center); if (output == 0) { throw new Exception("Unable to delete centers.,"); } else { trans.Complete(); trans.Dispose(); } } }, "DeleteCenter(Centers center)", log); return(output); }
public async Task <IActionResult> DeleteCenter(Guid centerId) { var center = await _centerRepository.GetCenterByIdAsync(centerId); if (center == null) { return(NotFound()); } _centerRepository.DeleteCenter(center); await _centerRepository.SaveChangesAsync(); return(NoContent()); }