Esempio n. 1
0
        public static DAL.Suggestion ToDAL(SuggestionDto suggestionDto)
        {
            DAL.Suggestion suggestion = new DAL.Suggestion()
            {
                SuggestionID          = suggestionDto.SuggestionID,
                SuggestionDescreotion = suggestionDto.Description,
                SuggestionTitle       = suggestionDto.Title,

                Address = new DAL.Address()
                {
                    city    = suggestionDto.City,
                    country = suggestionDto.Country,
                    street  = suggestionDto.Street,
                },

                gender = suggestionDto.Gender,
                hostId = suggestionDto.HostId,
            };
            suggestion.ServiceTypesToSuggestions = suggestionDto.ServicesType.ConvertAll <DAL.ServiceTypesToSuggestion>(s =>
            {
                return(new ServiceTypesToSuggestion()
                {
                    ServiceTypeListID = s,
                });
            });
            if (suggestionDto.RangeHours != null)
            {
                suggestion.HoursRange = new DAL.HoursRange()
                {
                    hours_end   = suggestionDto.RangeHours.MaxHour,
                    hours_start = suggestionDto.RangeHours.StartHour
                }
            }
            ;
            if (suggestionDto.RangeAge != null)
            {
                suggestion.ageRange = new DAL.ageRange()
                {
                    age_max = suggestionDto.RangeAge.MaxAge,
                    age_min = suggestionDto.RangeAge.MinAge,
                }
            }
            ;
            return(suggestion);
        }
    }
}
Esempio n. 2
0
        public static SuggestionDto ToDTO(DAL.Suggestion model)
        {
            List <int>    vs  = new List <int>();
            List <string> vss = new List <string>();

            if (model.ServiceTypesToSuggestions.Count > 0)
            {
                foreach (var item in model.ServiceTypesToSuggestions)
                {
                    vs.Add(item.ServiceTypeListID);
                }
            }
            if (model.ServiceTypesToSuggestions.Count > 0)
            {
                foreach (var item in model.ServiceTypesToSuggestions)
                {
                    vss.Add(item.ServiceTypeList.ServiceTypeName);
                }
            }

            SuggestionDto suggestionDto = new SuggestionDto()
            {
                SuggestionID     = model.SuggestionID,
                Description      = model.SuggestionDescreotion,
                Gender           = model.gender,
                ServicesTypeName = vss,
                Title            = model.SuggestionTitle,
                ServicesType     = vs,
                City             = model.Address.city,
                Country          = model.Address.country,
                Street           = model.Address.street,
                HostId           = model.hostId,
                //boo
            };
            List <bookedDateDto> bookedDateDto = new List <bookedDateDto>();

            if (model.bookedDates != null && model.bookedDates.Count > 0)
            {
                foreach (var item in model.bookedDates)
                {
                    bookedDateDto.Add(new DTO.bookedDateDto()
                    {
                        dateEnd   = item.dateEnd.Value,
                        dateStart = item.dateStart.Value
                    });
                }
            }
            suggestionDto.bookedDates = bookedDateDto;
            if (model.ageRange != null)
            {
                suggestionDto.RangeAge = new AgeRange()
                {
                    MaxAge = model.ageRange.age_max,
                    MinAge = model.ageRange.age_min,
                }
            }
            ;
            if (model.HoursRange != null)
            {
                suggestionDto.RangeHours = new DTO.HoursRange()
                {
                    MaxHour   = model.HoursRange.hours_end,
                    StartHour = model.HoursRange.hours_start
                }
            }
            ;
            return(suggestionDto);
        }
Esempio n. 3
0
        public static SuggestionDto ToDTO(DAL.Suggestion model, int travelerId = -1)
        {
            //List<int> vs = new List<int>();
            //List<string> vss = new List<string>();
            //if (model.ServiceTypesToSuggestions.Count > 0)
            //{
            //    foreach (var item in model.ServiceTypesToSuggestions)
            //    {
            //        vs.Add(item.ServiceTypeListID);
            //    }
            //}
            //if (model.ServiceTypesToSuggestions.Count > 0)
            //{
            //    //�� �� �����!!
            //    foreach (var item in model.ServiceTypesToSuggestions)
            //    {
            //        vss.Add(item.ServiceTypeList.ServiceTypeName);
            //    }
            //}
            List <ServiceTypeMapper> lstmp = new List <ServiceTypeMapper>();

            if (model.ServiceTypesToSuggestions.Count > 0)
            {
                foreach (var item in model.ServiceTypesToSuggestions)
                {
                    string s = "";

                    //if (item.ServiceTypeList != null)
                    //    s = item.ServiceTypeList.ServiceTypeName;
                    s = DAL.ManageServicesList.GetServiceNameById(item.ServiceTypeListID);
                    lstmp.Add(new ServiceTypeMapper()
                    {
                        IdServiceType = item.ServiceTypeListID, ServiceTypeName = s
                    });
                }
            }
            SuggestionDto suggestionDto = new SuggestionDto()
            {
                SuggestionID = model.SuggestionID,
                Description  = model.SuggestionDescreotion,
                Gender       = model.gender,
                // ServicesTypeName = vss, ServicesType = vs,
                Title          = model.SuggestionTitle,
                mapperServices = lstmp,
                City           = model.Address.city,
                Country        = model.Address.country,
                Street         = model.Address.street,
                HostId         = model.hostId,
                Status         = travelerId == -1 ? null : model.SuggestionTravelers?.FirstOrDefault(s => s.TravelerId == travelerId)?.Status
                                 //boo
            };
            List <DTO.bookedDate> bookedDateDto = new List <DTO.bookedDate>();

            if (model.bookedDates != null && model.bookedDates.Count > 0)
            {
                foreach (var item in model.bookedDates)
                {
                    bookedDateDto.Add(new DTO.bookedDate()
                    {
                        dateEnd   = item.dateEnd.Value,
                        dateStart = item.dateStart.Value
                    });
                }
            }
            suggestionDto.bookedDates = bookedDateDto;
            if (model.ageRange != null)
            {
                suggestionDto.RangeAge = new AgeRange()
                {
                    MaxAge = model.ageRange.age_max,
                    MinAge = model.ageRange.age_min,
                }
            }
            ;
            if (model.HoursRange != null)
            {
                suggestionDto.RangeHours = new DTO.HoursRange()
                {
                    MaxHour   = model.HoursRange.hours_end,
                    StartHour = model.HoursRange.hours_start
                }
            }
            ;
            return(suggestionDto);
        }
Esempio n. 4
0
        public static DAL.Suggestion ToDAL(SuggestionDto suggestionDto)
        {
            DAL.Suggestion suggestion = new DAL.Suggestion()
            {
                SuggestionID          = suggestionDto.SuggestionID,
                SuggestionDescreotion = suggestionDto.Description,
                SuggestionTitle       = suggestionDto.Title,

                Address = new DAL.Address()
                {
                    city    = suggestionDto.City,
                    country = suggestionDto.Country,
                    street  = suggestionDto.Street,
                },

                gender = suggestionDto.Gender,
                hostId = suggestionDto.HostId,
            };
            //suggestion.ServiceTypesToSuggestions = suggestionDto.ServicesType.ConvertAll<DAL.ServiceTypesToSuggestion>(s =>
            // {
            //     return new ServiceTypesToSuggestion()
            //     {
            //         ServiceTypeListID = s,

            //     };
            // });
            suggestion.ServiceTypesToSuggestions = suggestionDto.mapperServices.ConvertAll <DAL.ServiceTypesToSuggestion>(s =>
            {
                return(new ServiceTypesToSuggestion()
                {
                    ServiceTypeListID = s.IdServiceType,
                    // ServiceTypeList = new ServiceTypeList() { ServiceTypeListID = s.IdServiceType, ServiceTypeName = s.ServiceTypeName },
                });
            }
                                                                                                                          );
            if (suggestionDto.RangeHours != null)
            {
                suggestion.HoursRange = new DAL.HoursRange()
                {
                    hours_end   = suggestionDto.RangeHours.MaxHour,
                    hours_start = suggestionDto.RangeHours.StartHour
                }
            }
            ;
            if (suggestionDto.RangeAge != null)
            {
                suggestion.ageRange = new DAL.ageRange()
                {
                    age_max = suggestionDto.RangeAge.MaxAge,
                    age_min = suggestionDto.RangeAge.MinAge,
                }
            }
            ;
            suggestion.bookedDates = suggestionDto.bookedDates.ConvertAll <DAL.bookedDate>(s =>
            {
                return(new DAL.bookedDate()
                {
                    dateEnd = s.dateEnd, dateStart = s.dateStart,
                });
            });
            return(suggestion);
        }
    }
}
 static void Main(string[] args)
 {
     using (var db = new AgencyContext())
     {
         // Create
         Console.WriteLine("Inserting a new Client");
         Client c = new Client {
             FirstName = "Irina", LastName = "Ivanova", BankAccount = 0987654321
         };
         RealEstate re1 = new RealEstate {
             Price = 19000, Type = "1-room flat"
         };
         RealEstate re2 = new RealEstate {
             Price = 28500, Type = "2-room flat"
         };
         RealEstate re3 = new RealEstate {
             Price = 30000, Type = "3-room flat"
         };
         RealEstate re4 = new RealEstate {
             Price = 35000, Type = "4-room flat"
         };
         Suggestion suggestion = new Suggestion
         {
             Client = c
         };
         RealEstateSuggestion res1 = new RealEstateSuggestion
         {
             RealEstate = re1,
             Suggestion = suggestion
         };
         RealEstateSuggestion res2 = new RealEstateSuggestion
         {
             RealEstate = re2,
             Suggestion = suggestion
         };
         RealEstateSuggestion res3 = new RealEstateSuggestion
         {
             RealEstate = re3,
             Suggestion = suggestion
         };
         RealEstateSuggestion res4 = new RealEstateSuggestion
         {
             RealEstate = re4,
             Suggestion = suggestion
         };
         db.Add(c);
         db.Add(re1);
         db.Add(re2);
         db.Add(re3);
         db.Add(re4);
         db.Add(suggestion);
         db.Add(res1);
         db.Add(res2);
         db.Add(res3);
         db.Add(res4);
         db.SaveChanges();
         var blog = db.Clients;
         var s    = db.Suggestions;
         var res  = db.RealEstates;
     }
 }