예제 #1
0
        public void Update(Facility entity)
        {
            if (Guid.Empty == entity.FacilityGuid)
                throw new PrimaryKeyMissingException("Facility", entity, "update");

            try
            {
                using (PSS2012DataContext context = this.DataContext)
                {
                    // Get the entity to update.
                    Facility facilityToUpdate = GetByPK(entity.FacilityGuid);
                    context.Facilities.Attach(facilityToUpdate);

                    // Set the new values.
                    //facilityToUpdate.FacilityID = entity.FacilityID;
                    facilityToUpdate.FacilityName = entity.FacilityName;
                    facilityToUpdate.Exerpt = entity.Exerpt;
                    facilityToUpdate.Description = entity.Description;
                    facilityToUpdate.Address = entity.Address;
                    facilityToUpdate.CityStateZipGuid = entity.CityStateZipGuid;
                    facilityToUpdate.PhoneNumber = entity.PhoneNumber;
                    facilityToUpdate.Email = entity.Email;
                    facilityToUpdate.Website = entity.Website;
                    facilityToUpdate.ClientGuid = entity.ClientGuid;
                    facilityToUpdate.ListingTypeGuid = entity.ListingTypeGuid;
                    facilityToUpdate.PublicPhotoFileUri = entity.PublicPhotoFileUri;
                    facilityToUpdate.Latitude = entity.Latitude;
                    facilityToUpdate.Longitude = entity.Longitude;
                    facilityToUpdate.Price = entity.Price;

                    // Perform the update.
                    context.SubmitChanges();
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw this.HandleSqlException(ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Inserts facility business entity into the data store.
        /// </summary>
        /// <param name="entity">The facility business entity to insert.</param>
        /// <returns>The facility identifier.</returns>
        public Facility Insert(Facility entity)
        {
            //@@NEW - changed return type to entity type.
            try
            {
                using (PSS2012DataContext context = this.DataContext)
                {
                    entity.FacilityGuid = Guid.NewGuid();

                    context.Facilities.InsertOnSubmit(entity);
                    context.SubmitChanges();
                }

                //@@NEW - returning full entity.
                return entity;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw this.HandleSqlException(ex);
            }
        }
예제 #3
0
        public List<Facility> GetAllWithUndefined()
        {
            Facility undefinedFacility = new Facility()
            {
                FacilityGuid = Guid.Empty,
                FacilityID = 0,
                FacilityName = "Undefined",
                Exerpt = null,
                Description = null,
                Address = null,
                CityStateZipGuid = Guid.Empty,
                PhoneNumber = null,
                Email = null,
                Website = null,
                ClientGuid = Guid.Empty,
                ListingTypeGuid = Guid.Empty,
                PublicPhotoFileUri = null,
            };

            List<Facility> response = this.GetAll().ToList();
            response.Add(undefinedFacility);

            return response;
        }
예제 #4
0
        public Facility GetByPK(Guid facilityGuid)
        {
            if (Guid.Empty == facilityGuid)
            { return new Facility(); }

            try
            {
                Facility daFacility = new Facility();
                using (PSS2012DataContext context = this.DataContext)
                {
                    daFacility = (
                        from items in context.Facilities
                        where items.FacilityGuid == facilityGuid
                        select items).SingleOrDefault();
                }

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

                return daFacility;
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw this.HandleSqlException(ex);
            }
        }
예제 #5
0
        public static DA.Facility ToDataEntity(this BE.Facility beFacility)
        {
            DA.Facility facilityResult = new DA.Facility()
            {
                FacilityGuid = beFacility.FacilityGuid,
                FacilityID = beFacility.FacilityID,
                FacilityName = beFacility.FacilityName,
                Exerpt = beFacility.Exerpt,
                Description = beFacility.Description,
                Address = beFacility.Address,
                CityStateZipGuid = beFacility.CityStateZipGuid,
                PhoneNumber = beFacility.PhoneNumber,
                Email = beFacility.Email,
                Website = beFacility.Website,
                ClientGuid = beFacility.ClientGuid,
                ListingTypeGuid = beFacility.ListingTypeGuid,
                PublicPhotoFileUri = beFacility.PublicPhotoFileUri,
                Latitude = beFacility.Latitude,
                Longitude = beFacility.Longitude,
                Price=beFacility.Price
            };

            return facilityResult;
        }