コード例 #1
0
        public ServiceResult <bool> DeletePropertyTag(int id)
        {
            ServiceResult <bool> retVal = new ServiceResult <bool>();

            FVCP.Persistence.EF.PropertyTag dbItem = null;
            using (var db = new PropertyEntities())
            {
                dbItem = db.PropertyTags
                         .FirstOrDefault(x => x.Id == id);

                if (dbItem != null)
                {
                    db.PropertyTags.Remove(dbItem);
                    db.SaveChanges();

                    retVal.Data    = true;
                    retVal.Success = true;
                }
                else
                {   // Item doesn't exist.
                    retVal.Success = false;
                    retVal.ErrorID = "404";
                    retVal.Message = string.Format("Tag id '{0}' was not found.  Unable to delete property tag.",
                                                   id);
                }
            }

            return(retVal);
        }
コード例 #2
0
        public ServiceResult <IPropertyTag> UpdatePropertyTag(int id, string name)
        {
            ServiceResult <IPropertyTag> retVal = new ServiceResult <IPropertyTag>();

            FVCP.Persistence.EF.PropertyTag dbItem = null;
            using (var db = new PropertyEntities())
            {
                dbItem = db.PropertyTags
                         .FirstOrDefault(x => x.Id == id);

                if (dbItem != null)
                {
                    dbItem.Name = name;
                    db.SaveChanges();

                    PropertyTagFactory myFact = new PropertyTagFactory();
                    retVal.Data    = myFact.Create(GetPropertyTagById(id).Data);
                    retVal.Success = true;
                }
                else
                {   // Item doesn't exist.
                    retVal.Success = false;
                    retVal.ErrorID = "404";
                    retVal.Message = string.Format("Tag id '{0}' was not found.  Unable to update property tag '{1}'.",
                                                   id, name);
                }
            }

            return(retVal);
        }
コード例 #3
0
        public IPropertyTag GetPropertyTagById(int id)
        {
            FVCP.Persistence.EF.PropertyTag dbItem = null;
            using (var db = new PropertyEntities())
            {
                dbItem = db.PropertyTags
                         .FirstOrDefault(x => x.Id == id);
            }

            PropertyTagDTO     dto    = PropertyTagRepository.MapFieldValues(dbItem);
            PropertyTagFactory myFact = new PropertyTagFactory();
            IPropertyTag       retVal = myFact.Create(dto);

            return(retVal);
        }
コード例 #4
0
        public ServiceResult <IPropertyTag> AddPropertyTag(string pin, string name)
        {
            ServiceResult <IPropertyTag> retVal = new ServiceResult <IPropertyTag>();

            FVCP.Persistence.EF.PropertyTag dbItem = null;
            using (var db = new PropertyEntities())
            {
                dbItem = db.PropertyTags
                         .FirstOrDefault(x => x.Pin == pin && x.Name == name);

                if (dbItem == null)
                {   // Go ahead and add the item, it isn't a duplicate.
                    dbItem = new EF.PropertyTag()
                    {
                        Name = name,
                        Pin  = pin
                    };

                    db.PropertyTags.Add(dbItem);
                    db.SaveChanges();  // ID value should populate.

                    PropertyTagDTO     dto    = PropertyTagRepository.MapFieldValues(dbItem);
                    PropertyTagFactory myFact = new PropertyTagFactory();
                    retVal.Data    = myFact.Create(dto);
                    retVal.Success = true;
                }
                else
                {
                    retVal.Success = false;
                    retVal.ErrorID = "422";
                    retVal.Message = string.Format("Unprocessable Entity - Tag '{0}' already exists for PIN '{1}'", name, pin);
                }
            }

            return(retVal);
        }
コード例 #5
0
        public IProperty GetByPin(string pin)
        {
            FVCP.Persistence.EF.Property dbProperty = null;
            using (var db = new PropertyEntities())
            {
                dbProperty = db.Properties
                             .Include(x => x.PropertyAddress)
                             .Include(x => x.PropertyClass)
                             .Include(x => x.PropertyTags)
                             .Include(x => x.Township)
                             .FirstOrDefault(x => x.Pin == pin);
            }

            if (dbProperty == null)
            {
                return(null);
            }

            PropertyDTO     dto    = PropertyRepository.MapFieldValues(dbProperty);
            PropertyFactory myFact = new PropertyFactory();
            IProperty       retVal = myFact.Create(dto);

            return(retVal);
        }