//@@NEW public ListingType GetByListingTypeName(string listingTypeName) { if (string.IsNullOrEmpty(listingTypeName)) { return null; } try { ListingType daListingType = new ListingType(); using (PSS2012DataContext context = this.DataContext) { daListingType = ( from items in context.ListingTypes where items.ListingTypeName.ToLower() == listingTypeName.ToLower() select items).SingleOrDefault(); } return daListingType; } catch (System.Data.SqlClient.SqlException ex) { throw this.HandleSqlException(ex); } catch (Exception ex) { throw ex; } }
public List<ListingType> GetAllWithUndefined() { ListingType undefinedListingType = new ListingType() { ListingTypeGuid = Guid.Empty, ListingTypeName = "Undefined", }; List<ListingType> response = this.GetAll().ToList(); response.Add(undefinedListingType); return response; }
public void Update(ListingType entity) { if (Guid.Empty == entity.ListingTypeGuid) throw new PrimaryKeyMissingException("ListingType", entity, "update"); try { using (PSS2012DataContext context = this.DataContext) { // Get the entity to update. //ListingType listingTypeToUpdate = GetByPK(entity.ListingTypeGuid); ListingType listingTypeToUpdate = context.ListingTypes.Single(c => c.ListingTypeGuid == entity.ListingTypeGuid); // Set the new values. listingTypeToUpdate.ListingTypeName = entity.ListingTypeName; listingTypeToUpdate.ListingTypePrice = entity.ListingTypePrice; // context.ListingTypes.Attach(listingTypeToUpdate); // Perform the update. context.SubmitChanges(); } } catch (System.Data.SqlClient.SqlException ex) { throw this.HandleSqlException(ex); } catch (Exception ex) { throw ex; } }
/// <summary> /// Inserts listingType business entity into the data store. /// </summary> /// <param name="entity">The listingType business entity to insert.</param> /// <returns>The listingType identifier.</returns> public ListingType Insert(ListingType entity) { //@@NEW - changed return type to entity type. try { using (PSS2012DataContext context = this.DataContext) { entity.ListingTypeGuid = Guid.NewGuid(); context.ListingTypes.InsertOnSubmit(entity); context.SubmitChanges(); } //@@NEW - returning full entity. return entity; } catch (System.Data.SqlClient.SqlException ex) { throw this.HandleSqlException(ex); } catch (Exception ex) { throw ex; } }
public ListingType GetByPK(Guid listingTypeGuid) { if (Guid.Empty == listingTypeGuid) { return new ListingType(); } try { ListingType daListingType = new ListingType(); using (PSS2012DataContext context = this.DataContext) { daListingType = ( from items in context.ListingTypes where items.ListingTypeGuid == listingTypeGuid select items).SingleOrDefault(); } if (null == daListingType) { throw new DataAccessException("ListingType no longer exists."); } return daListingType; } catch (System.Data.SqlClient.SqlException ex) { throw this.HandleSqlException(ex); } catch (Exception ex) { throw ex; } }
public static DA.ListingType ToDataEntity(this BE.ListingType beListingType) { DA.ListingType listingTypeResult = new DA.ListingType() { ListingTypeGuid = beListingType.ListingTypeGuid, ListingTypeName = beListingType.ListingTypeName, ListingTypePrice=beListingType.ListingTypePrice }; return listingTypeResult; }