public FacilityOffering GetByPK(Guid facilityGuid, Guid offeringGuid)
        {
            if (Guid.Empty == facilityGuid || Guid.Empty == offeringGuid)
            { return new FacilityOffering(); }

            try
            {
                FacilityOffering daFacilityOffering = new FacilityOffering();
                using (PSS2012DataContext context = this.DataContext)
                {
                    daFacilityOffering = (
                        from items in context.FacilityOfferings
                        where items.FacilityGuid == facilityGuid && items.OfferingGuid == offeringGuid
                        select items).SingleOrDefault();
                }

                if (null == daFacilityOffering)
                {
                    throw new DataAccessException("FacilityOffering no longer exists.");
                }

                return daFacilityOffering;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw this.HandleSqlException(ex);
            }
        }
        /// <summary>
        /// Inserts facilityOffering business entity into the data store.
        /// </summary>
        /// <param name="entity">The facilityOffering business entity to insert.</param>
        /// <returns>The facilityOffering identifier.</returns>
        public FacilityOffering Insert(FacilityOffering entity)
        {
            //@@NEW - changed return type to entity type.
            try
            {
                using (PSS2012DataContext context = DataContext)
                {
                    context.FacilityOfferings.InsertOnSubmit(entity);
                    context.SubmitChanges();
                }

                //@@NEW - returning full entity.
                return entity;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw this.HandleSqlException(ex);
            }
        }
        public void Update(FacilityOffering entity)
        {
            if (Guid.Empty == entity.FacilityGuid || Guid.Empty == entity.OfferingGuid)
                throw new PrimaryKeyMissingException("FacilityOffering", entity, "update");

            try
            {
                using (PSS2012DataContext context = DataContext)
                {
                    // Get the entity to update.
                    FacilityOffering facilityOfferingToUpdate = GetByPK(entity.FacilityGuid, entity.OfferingGuid);

                    // Set the new values.
                    facilityOfferingToUpdate.IsChecked = entity.IsChecked;
                    context.FacilityOfferings.Attach(facilityOfferingToUpdate);

                    // Perform the update.
                    context.SubmitChanges();
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw this.HandleSqlException(ex);
            }
        }
Example #4
0
        public static DA.FacilityOffering ToDataEntity(this BE.FacilityOffering beFacilityOffering)
        {
            DA.FacilityOffering facilityOfferingResult = new DA.FacilityOffering()
            {
                FacilityGuid = beFacilityOffering.FacilityGuid,
                OfferingGuid = beFacilityOffering.OfferingGuid,
                IsChecked = beFacilityOffering.IsChecked,
            };

            return facilityOfferingResult;
        }