public void AddWorkslot(WorkSlotViewModel model)
 {
     foreach (var attribute in model.GetType().GetProperties())
     {
         if (attribute.PropertyType.Name == "Boolean" && (Boolean)attribute.GetValue(model) == true && attribute.Name.Substring(attribute.Name.Length - 3) == "day")
         {
             WorkSlot slot = new WorkSlot()
             {
                 StartTime = model.StartTime,
                 EndTime   = model.EndTime,
                 ServiceID = model.ServiceID,
                 DayName   = attribute.Name.Substring(2)
             };
             ServiceBusinessLayer.AddWorkSlot(slot);
         }
     }
 }
        public ActionResult ProfilePage(long id)
        {
            var medicalPlace = MedicalPlaceBusinessLayer.GetMedicalPlace(id);
            MedicalPlaceProfileViewModel model = new MedicalPlaceProfileViewModel()
            {
                MedicalPlaceID    = medicalPlace.ID,
                Services          = new List <ServiceViewModel>(),
                CareUnits         = new List <CareUnitViewModel>(),
                ServiceCategories = ServiceBusinessLayer.GetServiceCategories(),
                CareUnitTypes     = CareUnitBusinessLayer.GetCareUnitTypes(),
                IsAdmin           = medicalPlace.Admins.Select(m => m.Id).Contains(User.Identity.GetUserId <long>()),
                MedicalPlace      = medicalPlace,
                IsCurrentPlace    = Request.Cookies["placeInfo"] != null && Convert.ToInt64(Request.Cookies["placeInfo"].Values["id"]) == id?true : false,
            };


            foreach (var service in medicalPlace.Services)
            {
                var groupedSlots        = service.WorkSlots.GroupBy(slot => new { slot.StartTime, slot.EndTime });
                ServiceViewModel smodel = new ServiceViewModel()
                {
                    ID          = service.ID,
                    Name        = service.Name,
                    Cost        = service.Cost ?? 0,
                    Description = service.Description,
                    CategoryID  = service.CategoryID,
                    ProviderID  = service.ProviderID ?? 0,
                    WorkSlots   = new List <WorkSlotViewModel>()
                };
                foreach (var element in groupedSlots)
                {
                    WorkSlotViewModel wmodel = new WorkSlotViewModel();
                    wmodel.StartTime = element.Key.StartTime ?? TimeSpan.Zero;
                    wmodel.EndTime   = element.Key.EndTime ?? TimeSpan.Zero;
                    wmodel.ServiceID = service.ID;
                    foreach (var day in element)
                    {
                        switch (day.DayName)
                        {
                        case "Saturday":
                            wmodel.IsSaturday = true;
                            break;

                        case "Sunday":
                            wmodel.IsSunday = true;
                            break;

                        case "Monday":
                            wmodel.IsMonday = true;
                            break;

                        case "Tuesday":
                            wmodel.IsTuesday = true;
                            break;

                        case "Wednesday":
                            wmodel.IsWednesday = true;
                            break;

                        case "Thursday":
                            wmodel.IsThursday = true;
                            break;

                        case "Friday":
                            wmodel.IsFriday = true;
                            break;
                        }
                    }
                    smodel.WorkSlots.Add(wmodel);
                }
                model.Services.Add(smodel);
            }

            foreach (var careunit in medicalPlace.CareUnits)
            {
                CareUnitViewModel cmodel = new CareUnitViewModel()
                {
                    ID                 = careunit.ID,
                    Name               = careunit.Name,
                    CareUnitTypeID     = careunit.CareUnitTypeID,
                    AvailableRoomCount = careunit.AvailableRoomCount ?? 0,
                    Cost               = careunit.Cost,
                    ProviderID         = careunit.ProviderID,
                    Description        = careunit.Description,
                    LastUpdate         = careunit.LastUpdate
                };
                model.CareUnits.Add(cmodel);
            }

            return(View("ProfilePage", model));
        }