Esempio n. 1
0
 public long Save()
 {
     using (var db = new DB_RvsSettingsDataContext(SpecificInstances.DbFactory.CreateConnection()))
     {
         var row = SaveProperties(db);
         db.SubmitChanges();
         return(row.id);
     }
 }
Esempio n. 2
0
        public static bool DeleteProperties(long id)
        {
            using (var db = new DB_RvsSettingsDataContext(SpecificInstances.DbFactory.CreateConnection()))
            {
                var data = db.RVS_SavedProperties.
                           Where(r => r.id == id);
                if (UserRoles.IsInRole(UserRoles.AllowChangeOrDeleteJournalSettingsAsShared))
                {
                    data = data.Where(r => r.UserSID == User.GetSID() || r.isSharedView);
                }
                else
                {
                    data = data.Where(r => r.UserSID == User.GetSID());
                }

                var row = data.FirstOrDefault();
                if (row == null)
                {
                    return(false);
                }
                db.Connection.Open();
                DbTransaction transaction = null;
                try
                {
                    transaction    = db.Connection.BeginTransaction();
                    db.Transaction = transaction;
                    db.RVS_SavedProperties.DeleteOnSubmit(row);
                    db.RVS_Properties.DeleteOnSubmit(row.RVS_Property);
                    db.SubmitChanges();
                    transaction.Commit();
                }
                catch
                {
                    if (transaction != null)
                    {
                        transaction.Rollback();
                    }
                    return(false);
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Dispose();
                    }
                    db.Connection.Close();
                }
            }
            return(true);
        }
Esempio n. 3
0
        public void SaveWithViewSettings(SavingJournalSettings.SaveArgument argument, string conext)
        {
            if (!argument.saveFilters)
            {
                PageUrl = null;
            }
            using (var db = new DB_RvsSettingsDataContext(SpecificInstances.DbFactory.CreateConnection()))
            {
                db.Connection.Open();
                DbTransaction transaction = null;
                try
                {
                    transaction    = db.Connection.BeginTransaction();
                    db.Transaction = transaction;
                    var row = SaveProperties(db);
                    db.SubmitChanges();

                    RVS_SavedProperty viewRow = null;
                    if (argument.id != null)
                    {
                        var data = db.RVS_SavedProperties.
                                   Where(r => r.id == argument.id);
                        if (UserRoles.IsInRole(UserRoles.AllowChangeOrDeleteJournalSettingsAsShared))
                        {
                            data = data.Where(r => r.isSharedView || r.UserSID == User.GetSID());
                        }
                        else
                        {
                            data = data.Where(r => r.UserSID == User.GetSID());
                        }
                        viewRow = data.FirstOrDefault();
                    }
                    if (viewRow == null)
                    {
                        viewRow = new RVS_SavedProperty();
                        db.RVS_SavedProperties.InsertOnSubmit(viewRow);
                    }

                    viewRow.context         = conext;
                    viewRow.dateTime        = DateTime.Now;
                    viewRow.isDefaultView   = false;
                    viewRow.isSharedView    = argument.saveAsShared && UserRoles.IsInRole(UserRoles.AllowSaveJournalSettingsAsShared);
                    viewRow.JournalTypeName = JournalTypeName;
                    viewRow.nameRu          = argument.nameRu;
                    viewRow.nameKz          = argument.nameKz;
                    viewRow.UserSID         = User.GetSID();
                    viewRow.refProperties   = row.id;

                    db.SubmitChanges();
                    db.Transaction.Commit();
                }
                catch
                {
                    if (transaction != null)
                    {
                        transaction.Rollback();
                    }
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Dispose();
                    }
                    db.Connection.Close();
                }
            }
        }