public List<Client> GetAllWithUndefined() { Client undefinedClient = new Client() { ClientGuid = Guid.Empty, ClientID = 0, ClientName = "Undefined", PhoneNumber = null, Email = null, Address = null, CityStateZipGuid = Guid.Empty, PaymentInfoGuid = Guid.Empty, FederatedID = null, FederatedKey = null, FederatedIDProvider = null, Username = null, HashedPassword = null, AccountPaused = false }; List<Client> response = this.GetAll().ToList(); response.Add(undefinedClient); return response; }
public Client GetByEmail(string email) { if (string.IsNullOrEmpty(email)) { return new Client(); } try { Client daClient = new Client(); using (PSS2012DataContext context = this.DataContext) { daClient = ( from items in context.Clients where items.Email == email select items).Where(x=>x.IsActive==true).SingleOrDefault(); } if (null == daClient) { return null; } return daClient; } catch (System.Data.SqlClient.SqlException ex) { throw this.HandleSqlException(ex); } }
public void Update(Client entity) { if (Guid.Empty == entity.ClientGuid) throw new PrimaryKeyMissingException("Client", entity, "update"); try { using (PSS2012DataContext context = DataContext) { // Get the entity to update. //Client clientToUpdate = GetByPK(entity.ClientGuid); Client clientToUpdate = context.Clients.Single(c => c.ClientGuid == entity.ClientGuid); // Set the new values. //clientToUpdate.ClientID = entity.ClientID; clientToUpdate.ClientName = entity.ClientName; clientToUpdate.PhoneNumber = entity.PhoneNumber; clientToUpdate.Email = entity.Email; clientToUpdate.Address = entity.Address; clientToUpdate.CityStateZipGuid = entity.CityStateZipGuid; clientToUpdate.PaymentInfoGuid = entity.PaymentInfoGuid; clientToUpdate.FederatedID = entity.FederatedID; clientToUpdate.FederatedKey = entity.FederatedKey; clientToUpdate.FederatedIDProvider = entity.FederatedIDProvider; clientToUpdate.Username = entity.Username; clientToUpdate.HashedPassword = entity.HashedPassword; clientToUpdate.AccountPaused = entity.AccountPaused; clientToUpdate.IsWaiverd = entity.IsWaiverd; clientToUpdate.FreeDays = entity.FreeDays; clientToUpdate.Credits = entity.Credits; clientToUpdate.IsSuspended = entity.IsSuspended; clientToUpdate.IsFlagged = entity.IsFlagged; clientToUpdate.IsActive = entity.IsActive; // Perform the update. context.SubmitChanges(); } } catch (System.Data.SqlClient.SqlException ex) { throw this.HandleSqlException(ex); } }
/// <summary> /// Inserts client business entity into the data store. /// </summary> /// <param name="entity">The client business entity to insert.</param> /// <returns>The client identifier.</returns> public Client Insert(Client entity) { //@@NEW - changed return type to entity type. try { using (PSS2012DataContext context = DataContext) { entity.ClientGuid = Guid.NewGuid(); entity.ClientID = 1; context.Clients.InsertOnSubmit(entity); context.SubmitChanges(); } //@@NEW - returning full entity. return entity; } catch (System.Data.SqlClient.SqlException ex) { throw this.HandleSqlException(ex); } }
public Client GetByPK(Guid clientGuid) { if (Guid.Empty == clientGuid) { return new Client(); } try { Client daClient = new Client(); using (PSS2012DataContext context = this.DataContext) { daClient = ( from items in context.Clients where items.ClientGuid == clientGuid select items).SingleOrDefault(); } if (null == daClient) { throw new DataAccessException("Client no longer exists."); } return daClient; } catch (System.Data.SqlClient.SqlException ex) { throw this.HandleSqlException(ex); } }
public static DA.Client ToDataEntity(this BE.Client beClient) { DA.Client clientResult = new DA.Client() { ClientGuid = beClient.ClientGuid, ClientID = beClient.ClientID, ClientName = beClient.ClientName, PhoneNumber = beClient.PhoneNumber, Email = beClient.Email, Address = beClient.Address, CityStateZipGuid = beClient.CityStateZipGuid, PaymentInfoGuid = beClient.PaymentInfoGuid, FederatedID = beClient.FederatedID, FederatedKey = beClient.FederatedKey, FederatedIDProvider = beClient.FederatedIDProvider, Username = beClient.Username, HashedPassword = beClient.HashedPassword, AccountPaused = beClient.AccountPaused, IsWaiverd = beClient.IsWaiverd, FreeDays = beClient.FreeDays, Credits = beClient.Credits, IsSuspended = beClient.IsSuspended, IsFlagged=beClient.IsFlagged, IsActive = beClient.IsActive }; return clientResult; }