protected void DeletePlanAction(object sender, EventArgs e) { var request = new DeletePlanRequest { PlanId = this.PlanId, User = Users.Current }; var response = PlanService.DeletePlan(request); if (response.IsSuccessful) { UserMessage.SetSuccess(string.Format("Plan has been successfully deleted.")); } else { UserMessage.SetFailure(response.Message); } }
public DeletePlanResponse DeletePlan(DeletePlanRequest request) { var response = new DeletePlanResponse(); System.Threading.Thread.CurrentPrincipal = request.User.GetUserPrincipal(); #region Validation if (!PermitOnlyI()) { response.Message = Constants.Messages.NO_PERMISSIONS; return response; } var contracts = _contractRepository.FindByPlanId(request.PlanId); if (contracts.Count(c => c.ContractStatus != ContractStatus.Closed) > 0) { response.Message = "Cannot delete Plan that has active contracts"; return response; } #endregion try { using (var ts = new TransactionScope()) { if (_planRepository.DeletePlan(request.PlanId)) { response.IsSuccessful = true; ts.Complete(); } } } catch (Exception) { response.IsSuccessful = false; response.Message = Constants.Messages.INTERNAL_ERROR; } return response; }