//private House SetDefaultForHouse(House HouseObj) //{ // Type type = HouseObj.GetType(); // PropertyInfo[] properties = type.GetProperties(); // foreach (PropertyInfo property in properties) // { // if (property.PropertyType == typeof(decimal?)) // { // // if (property.GetType()== typeof(decimal?)) // //{ // if (property.GetValue(HouseObj, null) == null) // { // property.SetValue(HouseObj, (decimal)0, null); // } // } // else if (property.PropertyType == typeof(int?)) // { // // if (property.GetType()== typeof(decimal?)) // //{ // if (property.GetValue(HouseObj, null) == null) // { // property.SetValue(HouseObj, 0, null); // } // } // else if (property.PropertyType == typeof(bool?)) // { // // if (property.GetType()== typeof(decimal?)) // //{ // if (property.GetValue(HouseObj, null) == null) // { // property.SetValue(HouseObj, true, null); // } // } // Console.WriteLine("Name: " + property.Name + ", Value: " + property.GetValue(HouseObj, null)); // } // if (HouseObj.agencyCosts == null) // { // HouseObj.agencyCosts = 0; // } // return HouseObj; //} private UsaHouseDTO SetDefaultForHouseDTO(UsaHouseDTO HouseObj) { Type type = HouseObj.GetType(); PropertyInfo[] properties = type.GetProperties(); foreach (PropertyInfo property in properties) { if (property.PropertyType == typeof(decimal?)) { // if (property.GetType()== typeof(decimal?)) //{ if (property.GetValue(HouseObj, null) == null) { property.SetValue(HouseObj, (decimal)1, null); } } else if (property.PropertyType == typeof(int?)) { // if (property.GetType()== typeof(decimal?)) //{ if (property.GetValue(HouseObj, null) == null) { property.SetValue(HouseObj, 0, null); } } else if (property.PropertyType == typeof(bool?)) { // if (property.GetType()== typeof(decimal?)) //{ if (property.GetValue(HouseObj, null) == null) { property.SetValue(HouseObj, true, null); } } else if (property.PropertyType == typeof(double?)) { // if (property.GetType()== typeof(decimal?)) //{ if (property.GetValue(HouseObj, null) == null) { property.SetValue(HouseObj, 0, null); } } Console.WriteLine("Name: " + property.Name + ", Value: " + property.GetValue(HouseObj, null)); } if (HouseObj.agencyCosts == null) { HouseObj.agencyCosts = 0; } return(HouseObj); }
// GET: Houses/Details/5 public ActionResult Details(int?id) { var vm = InitializeIndexView(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UsaHousesPageManager UsaHousesPageManagerObj = new UsaHousesPageManager(); //Ls.Prj.Entity.House house = UsaHousesPageManagerObj.GetUsaHouse((int)id); UsaHouseDTO UsaHouseDTOObj = UsaHousesPageManagerObj.GetUsaHouseDTO((int)id); UsaHouseDTOObj = SetDefaultForHouseDTO(UsaHouseDTOObj); // house = SetDefaultForHouseEntity(house); //House house = db.House.Find(id); if (UsaHouseDTOObj == null) { return(HttpNotFound()); } RptHouseManagementManager ObjRptHouseManagementManager = new RptHouseManagementManager(); List <HouseReportDTO> LstRptDTO = new List <HouseReportDTO>(); LstRptDTO = ObjRptHouseManagementManager.GetReportsForHouses(UsaHouseDTOObj.Id.ToString()); // http://2.235.241.7:8080//houses/5/reports/years/2018 //********************* //codice vecchio //string report1 = Utility.ReadSetting("Re2017ApiUrl") + "/houses/" + UsaHouseDTOObj.Id + "/reports/years/2018"; // string report2 = Utility.ReadSetting("Re2017ApiUrl") + "/houses/" + UsaHouseDTOObj.Id + "/reports/years/2019"; //HouseReportDTO ObjHouseReportDTO1 = new HouseReportDTO(); //ObjHouseReportDTO1.reportUrl = report1; //ObjHouseReportDTO1.year = "2018"; //HouseReportDTO ObjHouseReportDTO2 = new HouseReportDTO(); //ObjHouseReportDTO2.reportUrl = report2; //ObjHouseReportDTO2.year = "2019"; //vm.ReportsUrl = new List<HouseReportDTO>() { ObjHouseReportDTO1, ObjHouseReportDTO2 }; ////********************* vm.ReportsUrl = LstRptDTO; vm.HouseDTO = UsaHouseDTOObj; //vm.House = house; return(View(vm)); //return View(house); }
public UsaHouseDTO GetUsaHouseDTO(int Id) { House ObjHouse = null; ObjHouse = GetAsyncUsaHouse("houses/" + Id.ToString()).Result; //mapping su DTO UsaHouseDTO ObjUsaHouseDTO = new UsaHouseDTO(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <House, UsaHouseDTO>() //.ForMember(dest => dest.enabled, opt => opt.MapFrom(src => (((bool)src.disabled) ? "NO" : "YES"))); .ForMember(dest => dest.country, opt => opt.MapFrom(src => src.country)); }); IMapper mapper = config.CreateMapper(); ObjUsaHouseDTO = mapper.Map <House, UsaHouseDTO>(ObjHouse); return(ObjUsaHouseDTO); }