public int Save(ObservableCollection <StaffInfoModel> models) { using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().BeginTransaction()) { try { int res = 0; var list = connect.FindAll <DBModels.PostgreSQL.Staff, int>(m => m.Id); var data = list.Where(w => !models.Select(s => s.Id).Contains(w.Id)); res += connect.Delete(data); foreach (StaffInfoModel model in models) { DBModels.PostgreSQL.Staff staff = new DBModels.PostgreSQL.Staff(); ModelHelper.CopyModel(staff, model); staff.SalonCode = model.Salon.Code; staff.Salon = connect.GetWhere <DBModels.PostgreSQL.Salon>(s => s.Code == model.Salon.Code).FirstOrDefault(); staff.Services = JsonConvert.SerializeObject(model.Services); staff.ServiceTimes = JsonConvert.SerializeObject(model.ServiceTimes); Func <DBModels.PostgreSQL.Staff, bool> func = m => { if (m.Id == staff.Id) { if (m.Code == staff.Code && m.Name == staff.Name && m.SalonCode == staff.SalonCode && m.Services == staff.Services && m.ServiceTimes == staff.ServiceTimes) { return(false); } else { return(true); } } return(false); }; if (model.Id < 1) { staff.CreateTime = DateTime.Now.ToLongDateString(); res += connect.Add(staff); } else if (list.Where(func).Count() > 0) { staff.UpdateTime = DateTime.Now.ToLongDateString(); res += connect.Modify(staff); } } connect.Commite(); return(res); } catch (Exception ex) { connect.Rollback(); AppLog.Error(typeof(StaffControl), ex.ToString()); throw new AppException("DBException"); } } }
public int Save(ObservableCollection <AssetsModel> models) { if (models.Count < 1) { return(0); } using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().BeginTransaction()) { try { int res = 0; var list = connect.GetWhere <DBModels.PostgreSQL.Assets>(m => m.SalonCode == models[0].SalonCode); var data = list.Where(w => !models.Select(s => s.Id).Contains(w.Id)); res += connect.Delete(data); foreach (AssetsModel model in models) { DBModels.PostgreSQL.Assets assets = new DBModels.PostgreSQL.Assets(); ModelHelper.CopyModel(assets, model); Func <DBModels.PostgreSQL.Assets, bool> func = m => { if (m.Id == assets.Id) { if (m.Code == assets.Code && m.Name == assets.Name && m.Price == assets.Price && m.Number == assets.Number && m.SalonCode == assets.SalonCode) { return(false); } else { return(true); } } return(false); }; if (model.Id < 1) { assets.CreateTime = DateTime.Now.ToLongDateString(); res += connect.Add(assets); } else if (list.Where(func).Count() > 0) { assets.UpdateTime = DateTime.Now.ToLongDateString(); res += connect.Modify(assets); } } connect.Commite(); return(res); } catch (Exception ex) { connect.Rollback(); AppLog.Error(typeof(AssetsControl), ex.ToString()); throw new AppException("DBException"); } } }
public int Save(ObservableCollection <SalonModel> models) { using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().BeginTransaction()) { try { int res = 0; var list = connect.FindAll <DBModels.PostgreSQL.Salon, int>(m => m.Id); var data = list.Where(w => !models.Select(s => s.Id).Contains(w.Id)); res += connect.Delete(data); foreach (SalonModel model in models) { DBModels.PostgreSQL.Salon salon = new DBModels.PostgreSQL.Salon(); ModelHelper.CopyModel(salon, model); Func <DBModels.PostgreSQL.Salon, bool> func = m => { if (m.Id == model.Id) { if (m.Code == model.Code && m.Name == model.Name && m.LocationCode == model.LocationCode && m.ManagerCode == model.ManagerCode) { return(false); } else { return(true); } } return(false); }; if (model.Id < 1) { salon.CreateTime = DateTime.Now.ToLongDateString(); res += connect.Add(salon); } else if (list.Where(func).Count() > 0) { salon.UpdateTime = DateTime.Now.ToLongDateString(); res += connect.Modify(salon); } } connect.Commite(); return(res); } catch (Exception ex) { connect.Rollback(); AppLog.Error(typeof(SalonControl), ex.ToString()); throw new AppException("DBException"); } } }
public int Save() { using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().BeginTransaction()) { try { int res = 0; var list = connect.FindAll <DBModels.PostgreSQL.Location, int>(m => m.Id); var data = list.Where(w => !_locations.Select(s => s.Id).Contains(w.Id)); res += connect.Delete(data); foreach (var model in _locations) { DBModels.PostgreSQL.Location location = new DBModels.PostgreSQL.Location(); ModelHelper.CopyModel(location, model); Func <DBModels.PostgreSQL.Location, bool> func = m => { if (m.Id == model.Id && m.Code.Equals(model.Code)) { if (m.City.Equals(model.City) && m.Province.Equals(model.Province)) { return(false); } else { return(true); } } return(false); }; if (model.Id < 1) { res += connect.Add(location); } else if (list.Where(func).Count() > 0) { res += connect.Modify(location); } } connect.Commite(); return(res); } catch (Exception ex) { connect.Rollback(); AppLog.Error(typeof(LocationMaster), ex.ToString()); throw new AppException("DBException"); } } }
public bool Insert() { return(DBFactory.Add(new MoonTestModel { Guid = Guid.NewGuid().ToString() }) != DBNull.Value); }