Example #1
0
        public void remove(SubscribedUser role)
        {
            StoreRole sr = role.getStoreRole(store);

            if (sr == null)
            {
                throw new RoleException("user " + role.getUsername() +
                                        " doesn't have a role in store "
                                        + store.getStoreName());
            }
            if (sr.getAppointedBy() != this.userName)
            {
                throw new RoleException("Error: User " + userName.getUsername() +
                                        " didn't appoint " +
                                        role.getUsername());
            }
            DBStore.getInstance().removeStoreRole(sr);
            role.removeStoreRole(sr);
            store.removeStoreRole(sr);
        }
Example #2
0
        public void addStoreRole(StoreRole sr)
        {
            //SqlConnection connection = Connector.getInstance().getSQLConnection();
            lock (connection)
            {
                if (ownerTrans == null)
                {
                    connection.Open();
                }

                SqlTransaction transaction;
                if (ownerTrans != null)
                {
                    transaction = ownerTrans;
                }
                else
                {
                    transaction = connection.BeginTransaction();
                }

                try
                {
                    string sql = "INSERT INTO [dbo].[StoreRoles] (storeId, appointedBy,userName,isOwner,editProduct,editDiscount,editPolicy)" +
                                 " VALUES (@storeId, @appointedBy, @userName,@isOwner,@editProduct,@editDiscount,@editPolicy)";
                    int    storeId     = sr.getStore().getStoreID();
                    string appointedBy = null;
                    if (sr.getAppointedBy() != null)
                    {
                        appointedBy = sr.getAppointedBy().getUsername();
                    }
                    string userName     = sr.getUser().getUsername();
                    int    isOwner      = sr.getIsOwner();
                    int    editProduct  = 1;
                    int    editDiscount = 1;
                    int    editPolicy   = 1;
                    if (isOwner == 0)
                    {
                        editProduct  = sr.GetPermissions().getPermission("editProduct");
                        editDiscount = sr.GetPermissions().getPermission("editDiscount");
                        editPolicy   = sr.GetPermissions().getPermission("editPolicy");
                    }
                    connection.Execute(sql, new { storeId, appointedBy, userName, isOwner, editProduct, editDiscount, editPolicy }, transaction);
                    storeRole.AddFirst(sr);
                    if (ownerTrans == null)
                    {
                        transaction.Commit();
                        transaction.Dispose();
                        connection.Close();
                    }
                }
                catch (Exception e)
                {
                    if (ownerTrans == null)
                    {
                        transaction.Dispose();
                        connection.Close();
                    }
                    SystemLogger.getErrorLog().Error("Connection error in function add role in DB Store while adding " + sr.getUser().getUsername());
                    throw new ConnectionException();
                }
            }
        }