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); }
public static PropertyDTO MapFieldValues(EF.Property dbItem) { if (dbItem == null) { return(null); } var myFact = new PropertyFactory(); PropertyDTO retVal = new PropertyDTO() { Age = dbItem.Age, AirCond = dbItem.AirCond, AptCount = dbItem.AptCount, AtticDesc = dbItem.AtticDesc, BasementDesc = dbItem.BasementDesc, BuildingSF = dbItem.BuildingSF, BuildingUse = dbItem.BuildingUse, ClassNum = dbItem.ClassNum, CommUnits = dbItem.CommUnits, ExtDesc = dbItem.ExtDesc, Fireplace = dbItem.Fireplace, FullBath = dbItem.FullBath, GarageDesc = dbItem.GarageDesc, HalfBath = dbItem.HalfBath, HomeImpYear = dbItem.HomeImpYear, LandSF = dbItem.LandSF, LocationId = dbItem.LocationId, NeighborhoodId = dbItem.NeighborhoodId, Pin = dbItem.Pin, PropertyAddressDTO = PropertyAddressRepository.MapFieldValues(dbItem.PropertyAddress), PropertyClassDTO = PropertyClassRepository.MapFieldValues(dbItem.PropertyClass), PropertyTagDTOs = PropertyTagRepository.MapFieldValues(dbItem.PropertyTags), ResType = dbItem.ResType, SaleAmount = dbItem.SaleAmount, SaleDate = dbItem.SaleDate, TaxCode = dbItem.TaxCode, TotalAllBuildingSF = dbItem.TotalAllBuildingSF, TownNum = dbItem.TownNum, TownshipDTO = TownshipRepository.MapFieldValues(dbItem.Township), UnitsTotal = dbItem.UnitsTotal, Volume = dbItem.Volume }; return(retVal); }
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); }