public ObservableCollection <StaffInfoModel> GetStaffInfosBySalon(string salonCode) { var models = new ObservableCollection <StaffInfoModel>(); using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().StartConnect()) { var listStaff = connect.GetWhere <DBModels.PostgreSQL.Staff>(w => w.SalonCode == salonCode).OrderBy(m => m.Code); foreach (var item in listStaff) { StaffInfoModel model = new StaffInfoModel(); ModelHelper.CopyModel(model, item); models.Add(model); } } return(models); }
public ObservableCollection <StaffInfoModel> GetAllStaffInfos() { var models = new ObservableCollection <StaffInfoModel>(); using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().StartConnect()) { var salons = new SalonControl().GetAllSalonInfos(); var listStaff = connect.FindAll <DBModels.PostgreSQL.Staff, string>(m => m.Code); foreach (var item in listStaff) { StaffInfoModel model = new StaffInfoModel(); ModelHelper.CopyModel(model, item); model.Salons = salons; model.Salon = salons.Where(s => s.Code == item.SalonCode).FirstOrDefault(); if (!string.IsNullOrEmpty(item.Services)) { model.Services = JsonConvert.DeserializeObject <ObservableCollection <ServiceModel> >(item.Services); } if (!string.IsNullOrEmpty(item.ServiceTimes)) { model.ServiceTimes = JsonConvert.DeserializeObject <ObservableCollection <StaffServiceTimeModel> >(item.ServiceTimes); } models.Add(model); } } return(models); //var Staffs = new ObservableCollection<StaffInfoModel>(); //DBConnect connect = new DBFactory().GetMongDBConnect(); //var list = connect.FindAll<DBModels.MongDB.Staff, ObjectId>(m => m.Id); //foreach (var staff in list) //{ // StaffInfoModel staffEdit = new StaffInfoModel(); // ModelHelper.CopyModel(staffEdit, staff); // staffEdit.Skills = new ObservableCollection<SkillModel>(); // foreach (var skill in staff.Skill) // { // SkillModel skillModel = new SkillModel(); // ModelHelper.CopyModel(skillModel, skill); // staffEdit.Skills.Add(skillModel); // } // Staffs.Add(staffEdit); //} //return Staffs; }
public StaffBookTimeEditViewModel() { try { Salons = new SalonControl().GetAllSalonInfos(); if (Salons.Count > 0) { Salon = Salons[0]; StaffInfos = new StaffControl().GetStaffInfosBySalon(Salon.Code); if (StaffInfos.Count > 0) { StaffInfo = StaffInfos[0]; BookTimes = new StaffBookTimeControl().GetBookTimesByStaff(StaffInfo.Code); } } } catch (Exception ex) { AppLog.Error(typeof(StaffServiceTimeEditViewModel), ex.ToString()); } }
public void LoadData(SalonModel salon) { try { if (salon != null) { StaffInfos = new StaffControl().GetStaffInfosBySalon(salon.Code); if (StaffInfos.Count > 0) { StaffInfo = StaffInfos[0]; } } else { StaffInfos.Clear(); } } catch (Exception ex) { AppLog.Error(typeof(StaffOrderEditViewModel), ex.ToString()); } }
public StaffListModel GetStaffInfosBySalon(string salonCode) { StaffListModel staffList = new StaffListModel(); staffList.Dates = GetDates(); staffList.StaffInfos = new List <StaffInfoModel>(); using (var context = new ApplicationDbContext()) { var listStaff = context.Staffs.Where(w => w.SalonCode == salonCode).OrderBy(m => m.Code); foreach (var item in listStaff) { StaffInfoModel model = new StaffInfoModel(); ModelHelper.CopyModel(model, item); model.ServiceTimes = new Dictionary <string, List <StaffServiceTimeModel> >(); List <StaffServiceTimeModel> servicestime = new List <StaffServiceTimeModel>(); if (!string.IsNullOrEmpty(item.ServiceTimes)) { servicestime = JsonConvert.DeserializeObject <List <StaffServiceTimeModel> >(item.ServiceTimes); } if (servicestime.Count > 0) { foreach (var date in staffList.Dates) { var booktimes = context.StaffBookTimes.Where(m => m.StaffCode == model.Code && m.Date == date).ToList(); var times = servicestime.Where(m => !booktimes.Any(m2 => m2.ServiceTimeCode == m.Code)).ToList(); times.ForEach(m => m.AreaTime = m.StartTime + '-' + m.EndTime); model.ServiceTimes.Add(date, times); } } staffList.StaffInfos.Add(model); } } return(staffList); }