Esempio n. 1
0
 public int Save(ObservableCollection <CustomModel> models)
 {
     if (models.Count < 0)
     {
         return(0);
     }
     using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().BeginTransaction())
     {
         try
         {
             int res = 0;
             foreach (CustomModel model in models)
             {
                 DBModels.PostgreSQL.Custom custom = new DBModels.PostgreSQL.Custom();
                 ModelHelper.CopyModel(custom, model);
                 custom.UpdateTime = DateTime.Now.ToLongDateString();
                 res += connect.Modify(custom);
             }
             connect.Commite();
             return(res);
         }
         catch (Exception ex)
         {
             connect.Rollback();
             AppLog.Error(typeof(CustomControl), ex.ToString());
             throw new AppException("DBException");
         }
     }
 }
Esempio n. 2
0
        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");
                }
            }
        }
Esempio n. 3
0
        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");
                }
            }
        }
Esempio n. 4
0
        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");
                }
            }
        }
Esempio n. 5
0
        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 int Upate(ObservableCollection <StaffBookTimeModel> models)
        {
            using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().BeginTransaction())
            {
                try
                {
                    int res  = 0;
                    var list = connect.FindAll <DBModels.PostgreSQL.StaffBookTime, int>(m => m.Id);
                    foreach (StaffBookTimeModel model in models)
                    {
                        DBModels.PostgreSQL.StaffBookTime staffBook = new DBModels.PostgreSQL.StaffBookTime();
                        ModelHelper.CopyModel(staffBook, model);

                        Func <DBModels.PostgreSQL.StaffBookTime, bool> func = m =>
                        {
                            if (m.Id == staffBook.Id)
                            {
                                if (m.ServiceTimeCode == staffBook.ServiceTimeCode)
                                {
                                    return(false);
                                }
                                else
                                {
                                    return(true);
                                }
                            }
                            return(false);
                        };
                        if (list.Where(func).Count() > 0)
                        {
                            staffBook.UpdateTime = DateTime.Now.ToLongDateString();
                            res += connect.Modify(staffBook);
                        }
                    }
                    connect.Commite();
                    return(res);
                }
                catch (Exception ex)
                {
                    connect.Rollback();
                    AppLog.Error(typeof(StaffServiceTimeControl), ex.ToString());
                    throw new AppException("DBException");
                }
            }
        }