public Validation CreateDonor(ref Donor donor, long currentUserId) { donor.AccountId = 123; //need to get the account that the user is currently in var val = _validator.ValidateNewDonor(donor); if (!val.IsValid) return val; var trans = _factory.BuildTransaction("CreateDonor"); try { _repo.Insert(ref donor, ref trans); trans.Commit(); } catch (Exception e) { trans.Rollback(); val.AddError(string.Format("Unable to create donor: {0}", e.Message)); } finally { trans.Dispose(); } return val; }
public Validation UpdateDonor(ref Donor donor, long currentUserId) { var val = _validator.ValidateExistingDonor(donor); if (!val.IsValid) return val; var trans = _factory.BuildTransaction("UpdateDonor"); try { _repo.Update(ref donor, ref trans); trans.Commit(); } catch (Exception e) { trans.Rollback(); val.AddError(string.Format("Unable to update donor: {0}", e.Message)); } finally { trans.Dispose(); } return val; }
public Validation ValidateNewDonor(Donor donor) { IAuctionTransaction trans = null; var val = new Validation(); if (string.IsNullOrEmpty(donor.Name)) { val.AddError("Name is empty"); } if (string.IsNullOrEmpty(donor.Address)) { val.AddError("Address is empty"); } if (string.IsNullOrEmpty(donor.Phone)) { val.AddError("Phone is empty"); } if (donor.AccountId == 0) { val.AddError("Account is not set"); } else if (_accountRepo.AccountExists(donor.AccountId, ref trans)) { val.AddError("Not set to a valid Account"); } return val; }