public override Data.Model.Client Save(Data.Model.Client client) { if (client.User_Id == Guid.Empty) { throw new ArgumentException("User id most be specified to save a client"); } var isNew = client.Id == Guid.Empty; var result = Persistor.Save(client); if (!isNew) { Persistor.Commit(); return(result); } foreach (var clientContact in client.Contacts) { clientContact.Client_Id = result.Id; ClientContactPersistor.Save(clientContact); } Persistor.Commit(); ClientContactPersistor.Commit(); return(result); }
/// <summary> /// Deactivates a user by the specified id. /// </summary> /// <param name="id">The user id.</param> public virtual void Deactivate(Guid id) { var user = Persistor.Get(id); user.Active = false; Persistor.Save(user); Persistor.Commit(); }
public override Data.Model.User Save(Data.Model.User user) { var result = Validator.Validate(user); if (result.IsValid) { var entity = Persistor.Save(user); Persistor.Commit(); return(entity); } var properties = result.Errors.Select(e => e.PropertyName).ToArray(); throw new ArgumentException("One or more properties a required", String.Join(", ", properties.ToArray())); }
public override bool Delete(Guid id) { if (id == Guid.Empty) { throw new ArgumentException("invoice id cannot be empty"); } var invoice = Persistor.Get(id); // verify that the invoice dosen't have any payments // we can't delete invoices that have payments if (invoice.Payments != null && invoice.Payments.Count > 0) { throw new NotImplementedException("an invoice that contains a payment can not be deleted"); } Persistor.Delete(id); return(Persistor.Commit() > 0); }
public virtual Data.Model.Invoice Save(Guid userId, Data.Model.Invoice invoice) { if (userId == Guid.Empty) { throw new ArgumentException("User id most be specified to save an invoice"); } if (invoice.Client_Id == Guid.Empty) { throw new ArgumentException("Client id most be specified to save an invoice"); } var isNew = invoice.Id == Guid.Empty; var result = Persistor.Save(invoice); if (!isNew) { Persistor.Commit(); (Persistor as Data.Persistor.Invoice).UpdateUserId(userId, invoice.Id); return(result); } foreach (var item in invoice.Items) { item.Invoice_Id = result.Id; InvoiceItemPersistor.Save(item); } Persistor.Commit(); if (invoice.Items.Any()) { InvoiceItemPersistor.Commit(); } (Persistor as Data.Persistor.Invoice).UpdateUserId(userId, invoice.Id); return(result); }